#include
#include
struct student {
int num;
char name[20];
float score[4];
};
void input(struct student a[], int);
void aver(struct student a[], int,struct student b[]);
void order(struct student a[], int);
void output(struct student a[], int,struct student b[]);
int main() {
struct student stu[100];
struct student b[100];
int n;
printf("请输入学生个数:");
scanf("%d", &n);
input(stu, n);
aver(stu, n,b);
order(stu, n);
output(stu, n,b);
return 0;
}
void input(struct student a[], int n) {
int i, j;
// printf("请输入学生的学号,姓名,英语,数学,物理,语文成绩:\n");
for (i = 0; i < n; i++) {
printf("请输入第%d个学生的学号,姓名,英语,数学,物理,语文成绩:\n", i + 1);
scanf("%d", &a[i].num);
//gets(a[i].name);
scanf("%s", &a[i].name);
for (j = 0; j < 4; j++)
scanf("%f", &a[i].score[j]);
}
}
void aver(struct student a[], int n,struct student b[]) {
int i=0, j;
for (i = 0; i < n; i++) {
b[i].score[0] = 0;
for (j = 0; j < 4; j++)
b[i].score[0] += a[i].score[j];
b[i].score[0] = b[i].score[0] / 4;
}
}
void order(struct student a[], int n) {
int i, j;
struct student t[1];
for (i = 1; i < n; i++)
for (j = 0; j < n - i; j++)
if (a[j].score[3] < a[j + 1].score[3]) {
t[1] = a[j];
a[j] = a[j + 1];
a[j + 1] = t[1];
}
}
void output(struct student a[], int n,struct student b[]) {
int i, j;
printf("学号\t姓名\t 英语\t 数学\t 物理\t 语文\t 平均成绩如下:\n");
for (i = 0; i < n; i++) {
printf("%d\t%s\t", a[i].num, a[i].name);
for (j = 0; j < 4; j++)
printf("%.2f\t", a[i].score[j]);
printf("%.2f", b[i].score[0]);
printf("\n");
}
}
帮你改了一些,看看测试:
#include
int main()
{ int i,n;
double sum=0;
scanf("%d",&n);
for(i=1; i<=n; i++)
sum+=i*i*1.0/(i+1);
printf("%f\n",sum);
return 0;
}
#include
void main( )
{
int i,n;
float sum=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
sum+=i*i/(i+1);
printf("sum=%f",sum);
return 0;
}