作者在 2011-05-13 12:49:44 发布以下内容
#include "stdio.h"
#include "stdlib.h"
#define N 3
struct student
{
char num[6];
char name[10];
int score[3];
float average;
}stu[N];
int main(void)
{
void print(struct student stu[10]);
int i,j;
for(i=0;i<N;i++)
{
printf("input No.: ");
scanf("%s",stu[i].num);
printf("Name: ");
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
{ printf("input score: ");
scanf("%d",&stu[i].score[j]); }
}
print(stu);
system("pause");
return 0;
}
void print(struct student stu[10])
{
float ave=0;
int i,j,temp=0;
int fscore;
for(i=0;i<N;i++)
{ ave=0;
for(j=0;j<3;j++)
{
ave+=stu[i].score[j];
stu[i].average=ave/5;
}
}
for(i=0;i<N;i++)
{
printf("No. %s Name:%s average:%5.2f\n",
stu[i].num,stu[i].name,stu[i].average);
for(j=0;j<3;j++)
printf("score: %d\n",stu[i].score[j]);
}
fscore=stu[0].score[0];
for(i=0;i<N;i++)
{for(j=0;j<3;j++)
if(fscore<stu[i].score[j])
temp=i;
}
printf("\nthe best student is : \n");
printf("No. %s Name:%s average:%5.2f\n",
stu[temp].num,stu[temp].name,stu[temp].average);
printf("input score:\n");
for(j=0;j<3;j++)
printf("score: %d\n",stu[temp].score[j]);
}
#include "stdlib.h"
#define N 3
struct student
{
char num[6];
char name[10];
int score[3];
float average;
}stu[N];
int main(void)
{
void print(struct student stu[10]);
int i,j;
for(i=0;i<N;i++)
{
printf("input No.: ");
scanf("%s",stu[i].num);
printf("Name: ");
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
{ printf("input score: ");
scanf("%d",&stu[i].score[j]); }
}
print(stu);
system("pause");
return 0;
}
void print(struct student stu[10])
{
float ave=0;
int i,j,temp=0;
int fscore;
for(i=0;i<N;i++)
{ ave=0;
for(j=0;j<3;j++)
{
ave+=stu[i].score[j];
stu[i].average=ave/5;
}
}
for(i=0;i<N;i++)
{
printf("No. %s Name:%s average:%5.2f\n",
stu[i].num,stu[i].name,stu[i].average);
for(j=0;j<3;j++)
printf("score: %d\n",stu[i].score[j]);
}
fscore=stu[0].score[0];
for(i=0;i<N;i++)
{for(j=0;j<3;j++)
if(fscore<stu[i].score[j])
temp=i;
}
printf("\nthe best student is : \n");
printf("No. %s Name:%s average:%5.2f\n",
stu[temp].num,stu[temp].name,stu[temp].average);
printf("input score:\n");
for(j=0;j<3;j++)
printf("score: %d\n",stu[temp].score[j]);
}