Tuesday, 17 January 2017

Write a program to input some record of student containing (Roll,Name,City , Marks of different subject) and print record of topper student?

Q : Write a program to input some record of student containing (Roll,Name,City , Marks of different subject) and print record of topper student?

Solution : 

/*  **************************************
         Girfa : Student Help
         Search Maximum obtain marks record from structure
         Programmer Name : Chandani Gupta
         for more program visit : http://girfahelp.blogspot.in/p/c-language-assignment.html
    ****************************************
*/
#include<stdio.h>
#include<conio.h>
struct stu
{
    int roll;
    char nm[20];
    char city[30];
    int  marks[3];
};
void main()
{
    struct stu ob[3];
    int i,j,sum=0,tmp,index=0;
    clrscr();

    for(i=0;i<3;i++)
    {
         printf("%d record entry",i+1);
         printf("\nenter roll>> ");
         scanf("%d",&ob[i].roll);
         printf("enter name>> ");
         fflush(stdin);
         gets(ob[i].nm);
         printf("enter city>> ");
         fflush(stdin);
         gets(ob[i].city);
         for(j=0;j<3;j++)
         {
             printf("enter %d'st marks>> ",j+1);
             scanf("%d", & ob[i].marks[j]);
         }
    }/*input complete*/
    /* Calculate Sum of first record */
    for(i=0;i<3;i++)
         sum=sum+ob[0].marks[i];
    /* Check maximum marks from remain records */
    for(i=1;i<3;i++)
    {
         tmp=0;
         for(j=0;j<3;j++)
             tmp+=ob[i].marks[j];
         if(tmp>sum)
         {
             sum=tmp;
             index=i;
         }

    }
    printf("\n\nRecord of Topper Student\n\n");
    printf("\n\troll\t%d",ob[index].roll);
    printf("\n\tname\t%s",ob[index].nm);
    printf("\n\tcity\t%s",ob[index].city);
    for(i=0;i<3;i++)
         printf("\n\tMarks %d=%d",i+1,ob[index].marks[i]);
    printf("\n\tTotal=%d",sum);
    getch();
}


No comments:

Post a Comment