void input (int n, int s);
void avg (int n, int s);
struct studentinfo
{
char name [50];
int id;
double marks [20];
double avg;
}std[100];
int main ()
{
int n,s,i;
printf("Number of student: ");
scanf("%d",&n);
printf("Number of subject: ");
scanf("%d",&s);
input(n,s);
avg (n,s);
for(i=0;i<n;i++)
{
printf("Name: %s; Roll: %d; Average: %.2lf\n",std[i].name,std[i].id,std[i].avg);
}
}
void input(int n,int s)
{
int i,j;
for(i=0;i<n;i++)
{
fflush(stdin);
printf("Name: ");
gets(std[i].name);
printf("ID: ");
scanf("%d",&std[i].id);
for(j=0;j<s;j++)
{
printf("Subject %d: ",j+1);
scanf("%lf",&std[i].marks[j]);
}
}
}
void avg(int n,int s)
{
int i,j;
double sum;
for(i=0;i<n;i++)
{
sum=0.0;
for(j=0;j<s;j++)
{
sum=sum+std[i].marks[j];
}
std[i].avg=sum/s;
}
}
No comments:
Post a Comment