为什么我的C语言程序是对的,还有问题啊.?

来源:百度知道 编辑:UC知道 时间:2024/05/14 04:54:42
已知N个学生的学号、姓名和4门功课的成绩,计算:

(1)每个学生的总分、平均分和每门课程的平均分。

#include <stdio.h>

#define N 2
struct student
{
char number[10];
char name[15];
int ke[4];
int z_fen;
float pj_fen;
};

void main()
{
int i;
struct student stu[N];
for(i=0;i<N;i++)
{
printf("please input the student's number: ");
scanf("%s",&stu[i].number[10]);
printf("please input the student's name: ");
scanf("%s",&stu[i].name[15]);
printf("please input the student's score: \n");
printf("the first: ");
scanf("%d",&stu[i].ke[0]);
printf("the second: ");
scanf("%d",&stu[i].ke[1]);
printf("the third: ");
scanf("%d",&stu[i].ke[2]);
printf("the fourth: ");
scanf("%d",&stu[i].ke

谁说你的程序是对的!语法错误!!程序本身的问题!!!
我给出一个修改过的吧!
你看注释过的有些是你原来错误的地方!
有些是不好的地方(比如那个宏,是不推荐的,最好换成常量),
另外输出格式也修改过,你可以运行看看,
并且所有分数都改成float的了(也应该是这样的吧?分数不会都是整数)
以下是程序:
#include <stdio.h>

//#define N 2
const int N = 2;
struct student
{
char number[10];
char name[15];
float ke[4];
float z_fen;
float pj_fen;
};

int _tmain(int argc, _TCHAR* argv[])
{
//int i;
struct student stu[N];
for(int i=0;i<N;i++)
{
printf("please input the student's number: ");
scanf("%s",&stu[i].number);//[10]);
printf("please input the student's name: ");
scanf("%s",&stu[i].name);//[15]);
printf("please input the student's score: \n");
printf("the first: ");
scanf("%f",&stu[i].ke[0]);
printf("the second: ");
scanf("%f",&