富裕县中医院 副院长:为什么我的C语言程序是对的,还有问题啊.?

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 15:33:14
已知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[3]);
stu[i].z_fen=stu[i].ke[0]+stu[i].ke[1]+stu[i].ke[2]+stu[i].ke[3];
stu[i].pj_fen=float(stu[i].z_fen/4);
}

printf("number name z_fen pj_fen\n");
for(i=0;i<N;i++)
{
printf("%s",stu[i].number[10]);
printf("%s",stu[i].name[15]);
printf("%d",stu[i].z_fen);
printf("%d",stu[i].pj_fen);
printf("\n");
}
}

运行后能够输入,到输出的时候就会弹出一个窗口:
"0x00403cec"指令引用的"0x00000033"内存.该内存不能为"read".
要终止程序,请单击"确定"
要调试程序,请单击"取消"

这是什么原因啊,高手帮忙看看啊,急用啊,谢谢啦!!!

谁说你的程序是对的!语法错误!!程序本身的问题!!!
我给出一个修改过的吧!
你看注释过的有些是你原来错误的地方!
有些是不好的地方(比如那个宏,是不推荐的,最好换成常量),
另外输出格式也修改过,你可以运行看看,
并且所有分数都改成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",&stu[i].ke[1]);
printf("the third: ");
scanf("%f",&stu[i].ke[2]);
printf("the fourth: ");
scanf("%f",&stu[i].ke[3]);
stu[i].z_fen=stu[i].ke[0]+stu[i].ke[1]+stu[i].ke[2]+stu[i].ke[3];
stu[i].pj_fen=(float)((stu[i].z_fen)/4);
}

printf("number\tname\tz_fen\tpj_fen\n");
for(int j=0;j<N;j++)
{
printf("%s\t",stu[j].number);//[10]);
printf("%s\t",stu[j].name);//[15]);
printf("%f\t",stu[j].z_fen);
printf("%f\t",stu[j].pj_fen);
printf("\n");
}
return 0;
}

C++自身问题 建议重装系统 再重装C++
学期开始的时候我们也是这样解决的

大哥了 那是C++么??? 可能是操作系统的问题 你在别的电脑上运行下试试...