Program a structure which reads ‘n’ students information (name,3 subjects marks) and calculate total marks, result print them in a particular format - 100 Most Important C# Programs

100 Most Important C# Programs

61. Program a structure which reads ‘n’ students information (name,3 subjects marks) and calculate total marks, result print them in a particular format.

Code:

# include <stdio.h>

# include <conio.h>

main( )

{

struct student

{

char name[20];

int m1,m2,m3, tot;

char result[10];

}stud[10];

int i,n;

clrscr( );

printf(“enter no of students \n”);

scanf(“%d”,&n);

for(i=0;i<n;i++)

{

printf(”enter %d student deatails \n”,i);

printf(”enter name\n”);

scanf(“%s”, stud[i].name);

printf(“enter marks of 3 subjects \n”);

scanf(“%d%d%d”,

&stud[i].m1,&stud[i].m2,&stud[i].m3);

stud[i].tot=stud[i].m1+stud[i].m2+stud[i].

m3;

if((stud[i].m1>35)&&(stud[i].m2>35)&&(

stud[i].m3>35))

strcpy(stud[i].result,”pass”);

else

strtcpy(stud[i].result,”fail”);

}

clrscr( );

printf(“name total result \n”);

for(i=0;i<n;i++)

{

printf(“%s %d %s \n”,

stud[i].name,stud[i].tot,stud[i].result);

}

getch( );

}