C program to read a three-dim (a x b x c) matrix where a = no of classes, b = no of sections, c = no of students. Print the results of students in each class. Functions : Note : write functions wherever appropriate.
Write a c program to read a three-dim (a x b x c) matrix where a = no of
classes,
b = no of sections, c = no of students. Print the results of students in
each
class. Functions : Note : write functions wherever appropriate.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int
m[2][3][3];
float
avg[2][3];
int
i, j, k;
float
sum = 0.0;
clrscr();
for(k=0;k<2;k++)
{
printf("Class
%d\n",k+1);
for(i=0;i<3;i++)
{
printf("Enter
student %d data:\n",i+1);
for(j=0;j<3;j++)
{
printf("\tEnter
marks for test %d: ",j+1);
scanf("%d",&m[k][i][j]);
sum
= sum + m[k][i][j];
}
avg[k][i]
= sum/3;
printf("\n");
printf("\n");
sum
= 0;
}
}//for
k
for(k=0;k<2;k++)
{
printf("\n Class %d",k+1);
printf("\n\nSr
No.\tTest1\tTest2\tTest3\tAvg\tGrade\n");
for(i=0;i<47;i++)
{
printf("-");
}
printf("\n");
for(i=0;i<3;i++)
{
printf("%d.",i+1);
for(j=0;j<3;j++)
{
printf("\t%d",m[k][i][j]);
}
printf("\t%.2f",avg[k][i]);
//chk
grade of student
if(avg[k][i]>=75)
{
printf("\tA");
}
else
if(avg[k][i]>=60 && avg[k][i]<75)
{
printf("\tB");
}
else
if(avg[k][i]>=50 && avg[k][i]<60)
{
printf("\tC");
}
else
if(avg[k][i]>=40 && avg[k][i]<50)
{
printf("\tD");
}
else
if(avg[k][i]<40)
{
printf("\tFail");
}
printf("\n");
}//for
i
for(i=0;i<47;i++)
{
printf("-");
}
}//for
k
getch();
}
/*Output
Class 1
Enter student 1 data:
Enter marks for test 1: 50
Enter marks for test 2: 50
Enter marks for test 3: 50
Enter student 2 data:
Enter marks for test 1: 60
Enter marks for test 2: 60
Enter marks for test 3: 60
Enter student 3 data:
Enter marks for test 1: 70
Enter marks for test 2: 70
Enter marks for test 3: 70
Class 2
Enter student 1 data:
Enter marks for test 1: 70
Enter marks for test 2: 70
Enter
marks for test 2: 70
Enter student 3 data:
Enter marks for test 1: 50
Enter marks for test 2: 50
Enter marks for test 3: 50
Enter student 3 data:
Enter marks for test 1: 60
Enter marks for test 2: 60
Enter marks for test 3: 60
Class 1
Sr No.
Test1 Test2 Test3
Avg Grade
-----------------------------------------------
1.
50 50 50
50.00 C
2.
60 60 60
60.00 B
3.
70 70 70
70.00 B
-----------------------------------------------
Class 2
Sr No.
Test1 Test2 Test3
Avg Grade
-----------------------------------------------
1.
70 70 70
70.00 B
2.
50 50 50
50.00 C
3.
60 60 60
60.00 B
-----------------------------------------------