Structure of 10 students with name,roll number, marks of five subject and who is topper in which subject as well as overall who is topper

 // Date : 24/09/2022

//Author : Niraj Rajendra Bhagvat 


#include<stdio.h>

struct student
{
    int roll;
    int eng,chem,phy,bio,math;
    int total;
    char name[20];
};

int main()
{
    struct student std[3];
    int n = sizeof(std)/sizeof(std[0]);
    int topper[5],Topper,T;
    int tot_sub[5];
    float avg_sub[5];
    float perc[n];
    int e,c,p,m,b;

    for(int i = 0; i<n; i++)
    {
        std[i].roll = i+1;

        printf("\nEnter the name of roll number %d : ",std[i].roll);
        scanf("%s",std[i].name);

eng:
        printf("\nEnter the marks of English out of hundred : ");
        scanf("%d",&std[i].eng);

        if(std[i].eng > 100 || std[i].eng < 0)
        {
            printf("\nERROR !\nPLEASE ENTER VALID MARKS !");
            goto eng;
        }

chem:
        printf("\nEnter the marks of Chemistry out of hundred : ");
        scanf("%d",&std[i].chem);

        if(std[i].chem > 100 || std[i].chem < 0)
        {
            printf("\nERROR !\nPLEASE ENTER VALID MARKS !");
            goto chem;
        }

phy:
        printf("\nEnter the marks of Physics out of hundred : ");
        scanf("%d",&std[i].phy);

        if(std[i].phy > 100 || std[i].phy < 0)
        {
            printf("\nERROR !\nPLEASE ENTER VAL miID MARKS !");
            goto phy;
        }

math:
        printf("\nEnter the marks of Maths out of hundred : ");
        scanf("%d",&std[i].math);

        if(std[i].math > 100 || std[i].math < 0)
        {
            printf("\nERROR !\nPLEASE ENTER VALID MARKS !");
            goto math;
        }

bio:
        printf("\nEnter the marks of Biology out of hundred : ");
        scanf("%d",&std[i].bio);

        if(std[i].bio > 100 || std[i].bio < 0)
        {
            printf("\nERROR !\nPLEASE ENTER VALID MARKS !");
            goto bio;
        }

        std[i].total = (std[i].eng)+(std[i].chem)+(std[i].phy)+(std[i].math)+(std[i].bio);
        perc[i] = ((float)std[i].total/5.0);

    }

    Topper = std[0].total;
    for(int i =0; i<n; i++)
    {
        if(std[i].total > Topper)
        {
            Topper = std[i].total;
            T = i;
        }
    }

    topper[0] = std[0].eng;
    for(int i = 0; i<n; i++)
    {
        if(std[i].eng > topper[0])
        {
            topper[0] = std[i].eng;
            e = i;
        }
    }
    topper[1] = std[0].chem;
    for(int i = 0; i<n; i++)
    {
        if(std[i].chem > topper[1])
        {
            topper[1] = std[i].chem;
            c = i;
        }
    }
    topper[2] = std[0].phy;
    for(int i = 0; i<n; i++)
    {
        if(std[i].phy > topper[2])
        {
            topper[2] = std[i].phy;
            p = i;
        }
    }
    topper[3] = std[0].math;
    for(int i = 0; i<n; i++)
    {
        if(std[i].math > topper[3])
        {
            topper[0] = std[i].math;
            m = i;
        }
    }
    topper[4] = std[0].bio;
    for(int i = 0; i<n; i++)
    {
        if(std[i].bio > topper[4])
        {
            topper[4] = std[i].bio;
            b = i;
        }
    }

    tot_sub[0] = 0;
    for(int i=0; i<n; i++)
    {
        tot_sub[0] += std[i].eng;
    }
    avg_sub[0] = (float)tot_sub[0]/n;

    tot_sub[1] = 0;
    for(int i=0; i<n; i++)
    {
        tot_sub[1] += std[i].phy;
    }
    avg_sub[1] = (float)tot_sub[1]/n;

    tot_sub[2] = 0;
    for(int i=0; i<n; i++)
    {
        tot_sub[2] += std[i].chem;
    }
    avg_sub[2] = (float)tot_sub[2]/n;

    tot_sub[3] = 0;
    for(int i=0; i<n; i++)
    {
        tot_sub[3] += std[i].math;
    }
    avg_sub[3] = (float)tot_sub[3]/n;

    tot_sub[4] = 0;
    for(int i=0; i<n; i++)
    {
        tot_sub[4] += std[i].bio;
    }
    avg_sub[4] = (float)tot_sub[4]/n;

    for(int i = 0; i<n; i++)
    {
        printf("\nRoll no. = %d\n",std[i].roll);
        printf("\nName : %s \n",std[i].name);
        printf("\nTotal marks = %d\n",std[i].total);
        printf("\nTotal percentage = %.2f %%\n",perc[i]);
    }

    printf("\nTopper is - \nRoll number %d) %s with %.2f %%\n\n",std[T].roll,std[T].name,perc[T]);

    printf("\nEnglish topper is %s with %d marks\n",std[e].name,topper[0]);

    printf("\nChemistry topper is %s with %d marks\n",std[c].name,topper[1]);

    printf("\nPhysics topper is %s with %d marks\n",std[p].name,topper[2]);

    printf("\nMaths topper is %s with %d marks\n",std[m].name,topper[3]);

    printf("\nBiology topper is %s with %d marks\n",std[b].name,topper[4]);

    printf("\nEnglish subject average = %.2f\n",avg_sub[0]);
    printf("\nPhysics subject average = %.2f\n",avg_sub[1]);
    printf("\nChemistry subject average = %.2f\n",avg_sub[2]);
    printf("\nMaths subject average = %.2f\n",avg_sub[3]);
    printf("\nBiology subject average = %.2f\n",avg_sub[4]);

    return 0;
}


Comments

Popular posts from this blog

Pointer to Matrix In C

Calculator in c programming language