Create structure student for counting the percentage of three subjects of five students - C - A6P1



Write a progran to create structure student for counting the percentage of three subjects of five students. 

#include<stdio.h>
#include<conio.h>
struct student
{
    int sub[3];
    float per;
}stud[5];

void main()
{
    int a,b;
    float total=0;
    clrscr();
    for(a=0;a<5;a++)
    {
        total=0;
        printf("\n:: Student %d ::\n",a+1);
        for(b=0;b<3;b++)
        {
            printf("Subject %d -> ",b+1);
            scanf("%d",&stud[a].sub[b]);
            total=total+stud[a].sub[b];
        }
        stud[a].per=total/3;
    }
    for(a=0;a<5;a++)
    {
        printf("\nPercentage of Student %d -> %.2f",a+1,stud[a].per);
    }
    getch();
}

Post a Comment