Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program to take numbers from an input file (input.dat), calculate the

ID: 3761745 • Letter: W

Question

Write a C program to take numbers from an input file (input.dat), calculate the sum and average of the numbers for each row, and display them in a form of table like the figure below both on screen and in an output file (result.out).

   

Use these numbers in the input file.
#1               #2               #3               4
-0.043200 -0.003471 0.000000 0.100233
-0.040326 -0.004851 -0.000737 0.022249
-0.018204 -0.004246 -0.001530 0.161792
0.022249 0.008891 0.004870   0.199106
0.074892 0.044237 0.032171 0.341021
0.129600 0.100233 0.089016 0.221134
0.174747 0.160100 0.161792 0.003478
0.200242 0.199106 0.214417 0.012351
0.174747 0.160100 0.161792 0.032452

Write a C program to take numbers from an input file (input.dat), calculate the sum and average of the numbers for each row, and display them in a form of table like the figure below both on screen and in an output file (result.out) 874892 i,044237 ,832171 0.34182 1 .492321 ·123011 8.174747 8.160188 .161792 Press any key to continue - Use these numbers in the input file

Explanation / Answer

#include<stdio.h>
#include<conio.h>
void main()
{
int c[10][10],i,j,a,b;
clrscr();
printf(" Enter Order of Matrix : ");
scanf("%d%d",&a,&b);
printf(" Enter Elements : ");
for(i=0;i<a;i++)
for(j=0;j<b;j++)
scanf("%d",&c[i][j]);
for(i=0;i<a;i++)
{
c[i][b]=0;
for(j=0;j<b;j++)
c[i][b]+=c[i][j];
}
for(j=0;j<b;j++)
{
c[a][j]=0;
for(i=0;i<a;i++)
c[a][j]+=c[i][j];
}
c[a][b]=0;
for(i=0;i<a;i++)
c[a][b]+=c[i][b];
for(i=0;i<a+1;i++)
{
for(j=0;j<b+1;j++)
{
printf("%d",c[i][j]);
printf(" ");
}
printf(" ");
}
getch();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote