Nested Loop

This is a discussion on Nested Loop within the C Programming forums, part of the General Programming Boards category; I need some help creating a nested loop in the last for loop of columns of the matrix... The program ...

  1. #1
    Unregistered
    Guest

    Nested Loop

    I need some help creating a nested loop in the last for loop of columns of the matrix...

    The program accepts input and creates output. It is pretty much a Coef System of linear equations

    1.0 2.0 3.0 10.0
    4.0 5.0 6.0 20.0
    7.0 8.0 9.0 30.0

    Here is the code:

    #include<stdio.h>
    #include<conio.h>
    #include<math.h>

    void (main void)
    {
    int i,j;
    FILE*outptr;
    outptr=fopen("matrix.txt","wt")
    double x,y;
    double A[3][3],B[3],X[3];

    fprint(outptr,"This is a coefficient of linear equations\n")
    printf("Please enter A[3][3] Row by Row: \n")
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    scanf("%lf",&A[i][j]);

    printf("Please enter B[3], and the RHS vector, starting from row 1: \n")

    for(i=0;i<3;i++)
    scanf("%lf",&B[i]);

    printf("\n")

    for(i=0;i<3;i++)
    {
    printf("%3.1lf %3.1lf %3.1lf %3.1lf", A[i][0],A[i][l]\
    ,A[i][2],B[i]);
    fprintf(outptr,"3.1lf %3.1lf %3.1lf %3.1lf\n",\
    A[i][0],A[i][l],A[i][2],B[i]");
    fprintf(outptr, "\n");
    }

    getch();
    fclose(outptr)
    }

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    52

    I am not very good but try this....

    #include<stdio.h>
    #include<conio.h>
    #include<math.h>

    double x,y;
    double A[3][3],B[3],X[3];

    void main (void)
    {
    int i,j;
    FILE*outptr;
    outptr=fopen("matrix.txt","wt");
    fprint(outptr,"This is a coefficient of linear equations\n");
    printf("Please enter A[3][3] Row by Row: \n");
    for(i=0;i<3;i++)
    for(j=0;j<3;j++)
    scanf("%lf",&A[i][j]);

    printf("Please enter B[3], and the RHS vector, starting from row 1: \n");

    for(i=0;i<3;i++)
    scanf("%lf",&B[i]);

    printf("\n");

    for(i=0;i<3;i++)
    {
    for(j=0; j < 2; j++)
    {
    fprintf(outprt,"3.1lf", A[i][j]);
    }
    printf("%3.1lf", B[i]);
    fprintf(outptr, "\n");
    }

    getch();
    fclose(outptr)
    }

    I think that will work, however I did not run it through the compilier.
    Last edited by Halo; 05-07-2002 at 01:48 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. nested loop, simple but i'm missing it
    By big_brother in forum C Programming
    Replies: 19
    Last Post: 10-23-2006, 11:21 PM
  2. Nested for loop...search & display a list within a list
    By chadsxe in forum C++ Programming
    Replies: 13
    Last Post: 07-20-2005, 02:34 PM
  3. output from nested while loop
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 08-22-2002, 10:30 AM
  4. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 09:15 AM
  5. Need help with simple programs...
    By BCole19 in forum C++ Programming
    Replies: 22
    Last Post: 08-30-2001, 10:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21