# Nested Loop

• 05-06-2002
Unregistered
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)
}
• 05-07-2002
Halo
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.