#include<stdio.h>
#include<conio.h>
struct marks
{
int sub1;
int sub2;
int sub3;
int total;
};
void main()
{
int i;
struct marks student[3]={{45,61,71,0},{61,72,75,0},{51,55,66,0}};
struct marks total;
clrscr();
total.sub1=0;
total.sub2=0;
total.sub3=0;
total.total=0;
for(i=0;i<=2;i++)
{
student[i].total=student[i].sub1+student[i].sub2+student[i].sub3;
total.sub1=total.sub1+student[i].sub1;
total.sub2=total.sub2+student[i].sub2;
total.sub3=total.sub3+student[i].sub3;
total.total=total.total+student[i].total;
}
printf("Student total\n");
for(i=0;i<=2;i++)
printf("student[%d] %d\n",i+1,student[i].total);
printf("Subject total\n");
printf("%s %d\n%s %d\n%s %d\n","subject1",total.sub1,"subject2",total.sub2,"subject3",total.sub3);
printf("\nGrand total=%d\n",total.total);
getch();
#include<conio.h>
struct marks
{
int sub1;
int sub2;
int sub3;
int total;
};
void main()
{
int i;
struct marks student[3]={{45,61,71,0},{61,72,75,0},{51,55,66,0}};
struct marks total;
clrscr();
total.sub1=0;
total.sub2=0;
total.sub3=0;
total.total=0;
for(i=0;i<=2;i++)
{
student[i].total=student[i].sub1+student[i].sub2+student[i].sub3;
total.sub1=total.sub1+student[i].sub1;
total.sub2=total.sub2+student[i].sub2;
total.sub3=total.sub3+student[i].sub3;
total.total=total.total+student[i].total;
}
printf("Student total\n");
for(i=0;i<=2;i++)
printf("student[%d] %d\n",i+1,student[i].total);
printf("Subject total\n");
printf("%s %d\n%s %d\n%s %d\n","subject1",total.sub1,"subject2",total.sub2,"subject3",total.sub3);
printf("\nGrand total=%d\n",total.total);
getch();
}
Comments
Post a Comment