22. Write a program to calculate average and total of 5 students for 3 subjects (use nested for loops)
#include<stdio.h> #include<conio.h> void main() { int i,j,std[5][3]; float sum[5],avg[5]; printf("Enter the marks of students:\n"); for(i=0;i<5;i++) { for(j=0;j<3;j++) { scanf("%d",&std[i][j]); } } for(i=0;i<5;i++) { for(j=0;j<3;j++) { printf("%d ",std[i][j]); } printf("\n"); } for(i=0;i<5;i++) { for(j=0;j<3;j++) { sum[i]=sum[i]+std[i][j]; } } for(i=0;i<5;i++) { for(j=0;j<3;j++) { avg[i]=sum[i]/3; } } for(i=0;i<5;i++) { printf("sum[%d]=%f ",i,sum[i]); printf("avg[%d]=%f\n",i,avg[i]); } getch(); } #OUTPUTS: