im having problem of printing an array thats not from file but from data iv worked out using the summation. il post what i have done so far.
CODE
#include <stdio.h>
#define M 21
#define N 2
void main ()
{
float a[M][N];
FILE *ifp, *ofp;
int i, j;
float sum_x, sum_x2, sum_x3, sum_x4;
float sum_y, sum_yx, sum_yx2;
float delta_array[3][3], a1, a2, a3;
for(i=0;i<M;i++)
{
for(j=0;j<N;j++)
{
a[i][j]=0;
}
}
ifp=fopen("in.dat.txt", "r");
for(i=0; i<M; i++)
{
for(j=0;j<N;j++)
{
fscanf(ifp," %f", &a[i][j]);
printf("%9.3f\t", a[i][j]);
}
printf("\n");
}
for(i=0; i<M; i++)
{
sum_x+=a[i][0];
sum_y+=a[i][1];
sum_x2+=sum_x*sum_x;
sum_x3+=sum_x2*sum_x;
sum_x4+=sum_x3*sum_x;
sum_yx+=sum_y*sum_x;
sum_yx2+=sum_y+sum_x2;
}
printf("\n");
printf("The sum of x is %f\n", sum_x);
printf("The sum of y is %f\n", sum_y);
printf("The sum of x^2 is %f\n", sum_x2);
printf("The sum of x^3 is %f\n", sum_x3);
printf("The sum of x^4 is %f\n", sum_x4);
printf("The sum of y*x is %f\n", sum_yx);
printf("The sum of y*x^2 is %f\n", sum_yx2);
delta_array= {{M, sum_x, sum_x2}, {sum_x, sum_x2, sum_x3}, {sum_x2, sum_x3, sum_x4}};
for(i=0; i<3; i++)
{
for(j=0;j<3;j++)
{
printf("Delta array[%f][%f]\n %f", i, j, delta_array);
}
printf("\n");
}
getchar();
}
so if someone can tell me what im doing wrong and what i need to do to correct it it'l help with the other 3 arrays that i need to make as well.
Regards Nir03