Sunday, February 1, 2015
Matrix addition function load file in C
#include<stdio.h>
void read(float A[10][10])
{
int i,j;
FILE *inputMatrix=fopen("filein.txt","r");
for(i=0;i<3;++i){
for(j=0;j<3;++j){
fscanf(inputMatrix,"%f",&A[i][j]);
}
}
fclose(inputMatrix);
}
void add(float A[10][10],float B[10][10],float C[10][10])
{
int i,j;
for(i=0;i<3;++i)
{
for(j=0;j<3;++j)
{
C[i][j] = (A[i][j] + B[i][j]);
}
}
}
void print(float D[10][10])
{
int i,j;
for(i=0;i<3;++i)
{
for(j=0;j<3;++j)
{
printf("%f ",D[i][j]);
}
printf("\n");
}
}
main()
{
float A[10][10],C[10][10];
int i,j;
read(A);
add(A,A,C);
print(C);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment