计算平均分

来源:百度知道 编辑:UC知道 时间:2024/05/26 12:45:09
let score struct is defined as:
struct score
{
int result; //0-100,to store the result of some course
char course[20]; //to store the name of the course
}c07[20];
suppose all the values had been initialized properly before, wirte a program to calculate the average score of this course.

#include<stdio.h>
#include<stdlib.h>
#include <ctype.h>

struct score
{
int result; //0-100,to store the result of some course
char course[20]; //to store the name of the course
}c07[20];

void main()
{
int i,sum=0;
float average=0;

for(i=0;i<20;i++)
{
printf("Enter the score:\n");
fflush(stdin);
scanf("%d",&c07[i].result);
}
printf("Enter the course name:\n");
fflush(stdin);
gets(c07->course);

for (i=0;i<20;i++)
{
sum+=c07[i].result;
}
average=(float)sum/20;
printf("course:\n%s\naverage:\n%.2f\n",c07->course,average);
}
不知道满不满足你的要求
如果你要更详细的 功能更大的
我也可以帮你写
希望可以联系下
谢谢