C语言编程问题

[复制链接]
查看11 | 回复1 | 2009-10-17 22:13:02 | 显示全部楼层 |阅读模式
#define N 5#include "stdio.h"#include "stdlib.h"struct student{
char name[5];
int score[4];
int tot;};void main(){
student stu1[N],temp;
int i,j;
for(i=0;istu1.tot);
{
temp=stu1;
stu1=stu1[j];
stu1[j]=temp;
}
system("cls");/*输出*/
printf("Name\tTotal\tS1\tS2\tS3\tS4\n");
for(i=0;i<N;i++)
{
printf("%s\t%d\t%d\t%d\t%d\t%d\n",stu1.name,stu1.tot,stu1.score[0],stu1.score[1],stu1.score[2],stu1.score[3]);
}
system("pause");}
回复

使用道具 举报

千问 | 2009-10-17 22:13:02 | 显示全部楼层
for(i=0;i<N;i++){scanf("%s%d%d",&stu1.name); //这个地方输入有误;要想输入name应该是for(i=0;i<N;i++){scanf("%s",&stu1.name);后边对应输出也是有误,并且这个for(i=0;i<N;i++){scanf("%s%d%d",&stu1.name); stu1.tot=0; for(j=0;j<5;j++) {scanf("%d",&stu1.score[j]);
stu1.tot=stu1.tot+stu1.score[j]; } } 也不是应该嵌套使用for来输入数据啊;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行