C File =>
/* Write a C program to create a structure named student that accepts student roll no, name and marks of 3 subjects. Calculate the total of marks and percentage. Create an array of structures to enter information for n students and display the details. */
#include<stdio.h>
typedef struct Student
{
int rno;
char name[30];
int m1,m2,m3;
};
int main()
{
struct Student s[50];
int n,i,total[50];
float perc[50];
printf("\n How many students? ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n\n Enter Roll no %d : ",i+1);
scanf("%d",&s[i].rno);
printf("\n Enter name%d : ",i+1);
scanf("%s",s[i].name);
printf("\n Enter makrs1, marks2 and marks3 : ");
scanf("%d%d%d",&s[i].m1,&s[i].m2,&s[i].m3);
//calculating total and percentage
total[i]=s[i].m1+s[i].m2+s[i].m3;
perc[i]=(total[i])/3;
}
printf("\n\n Details are : ");
for(i=0;i<n;i++)
{
printf("\n\n Roll number : %d",s[i].rno);
printf("\n Name : %s",s[i].name);
printf("\n Marks1 : %d \n Marks2 : %d \n Marks3 : %d",s[i].m1,s[i].m2,s[i].m3);
printf("\nTotal : %d",total[i]);
printf("\n Percentage : %f",perc[i]);
}
return 0;
}
Comments
Post a Comment
Please do not enter any spam link in message.