Structure in C-1

Question: Write a program in C using struct for displaying results in order for 3 students.The program used include name,marks in 6 subjects,total and average. it should print result in table form

#include <stdio.h>
#include <stdlib.h>
struct
{
    char fn[12],ln[8];
    int sn,cpl,che,mat,egp,phy,acs,t;
    float per;
}student[2];
int main()
{
    int i=0,tmp,j=0;
    for(i=0;i<3;i++)
    {
        printf("Enter student %d first name:",i+1);
        scanf("%s",student[i].fn);
        printf("Enter student %d second name:",i+1);
        scanf("%s",student[i].ln);
        printf("Enter student number:");
        scanf("%d",&student[i].sn);
        printf("Enter CPL101 marks:");
        scanf("%d",&student[i].cpl);
        printf("Enter CHE101 marks:");
        scanf("%d",&student[i].che);
        printf("Enter MAT101 marks:");
        scanf("%d",&student[i].mat);
        printf("Enter EGP101 marks:");
        scanf("%d",&student[i].egp);
        printf("Enter PHY101 marks:");
        scanf("%d",&student[i].phy);
        printf("Enter ACS101 marks :");
        scanf("%d",&student[i].acs);
        student[i].t = student[i].acs+student[i].phy+student[i].mat+student[i].che+student[i].egp+student[i].cpl;
        student[i].per=student[i].t/6;
    }
       for(i=0; i<3; i++)
    {
        for(j=i+1; j<=3; j++)
        {
            if(student[i].per <student[j].per)
            {
                tmp = student[i].per;
                student[i].per = student[j].per;
               student[j].per = tmp;
            }
        }
    }
    printf("\nstd.no        name       cpl        che        mat       egp       phy        acs           total           per\n");
        for(i=0; i<3; i++)
    {
        printf("%d\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%f\n",student[i].sn,student[i].fn,student[i].ln,student[i].cpl,student[i].che,student[i].mat,student[i].egp,student[i].phy,student[i].acs,student[i].t,student[i].per);


    }
}

Output

Posted in

1 comment:

  1. Solve some pointer question also ��

    ReplyDelete