结果在添加数组中是错误的
没有最后一行的每一行都是人在数学,英语,kor,科学上的得分。
我的意思是arr [0] [0]
= person 1的数学分数:
arr[0][1] = person 1's eng score
arr[0][2] = person 1's kor score
arr[0][3] = person 1's science score
arr[0][4] = person 1's sum at each subject score
and arr[4][0] = sum at person 1,2,3,4's math score
此代码在Mac中的VSCODE运行
#include <stdio.h>
int main(void)
{
long i,j;
int arr[5][5];
printf("성적관리 프로그램 입니다.\n");
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
switch (j)
{
case 0:
printf("국어 점수를 입력해 주세요: \n");
scanf("%d",&arr[i][j]);
break;
case 1:
printf("영어 점수를 입력해 주세요: \n");
scanf("%d",&arr[i][j]);
break;
case 2:
printf("수학 점수를 입력해 주세요: \n");
scanf("%d",&arr[i][j]);
break;
case 3:
printf("국사 점수를 입력해 주세요: \n");
scanf("%d",&arr[i][j]);
break;
default:
printf("오류 발생");
}
}
}
printf("개인 별 총점을 구하겠습니다.\n");
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
arr[i][4] += arr[i][j];
}
}
printf("과목 별 총점을 구하겠습니다.\n");
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
arr[4][i] += arr[j][i];
}
}
for(i=0; i<4; i++)
{
arr[4][4] += arr[4][i];
}
for(i=0; i<5; i++)
{
for(j=0; j<5; j++)
{
printf("%3d ", arr[i][j]);
}
printf("\n");
}
return 0;
}
。结果是:
1 2 3 4 10
1 2 3 4 10
1 2 3 4 11
1 2 3 4 1874065002
5 6040476 708575245 2898508 71751423
Each row without last row is person's score at math, eng, kor, science.
I mean that arr[0][0]
= person 1's math score:
arr[0][1] = person 1's eng score
arr[0][2] = person 1's kor score
arr[0][3] = person 1's science score
arr[0][4] = person 1's sum at each subject score
and arr[4][0] = sum at person 1,2,3,4's math score
and this code is run at vscode in mac
#include <stdio.h>
int main(void)
{
long i,j;
int arr[5][5];
printf("성적관리 프로그램 입니다.\n");
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
switch (j)
{
case 0:
printf("국어 점수를 입력해 주세요: \n");
scanf("%d",&arr[i][j]);
break;
case 1:
printf("영어 점수를 입력해 주세요: \n");
scanf("%d",&arr[i][j]);
break;
case 2:
printf("수학 점수를 입력해 주세요: \n");
scanf("%d",&arr[i][j]);
break;
case 3:
printf("국사 점수를 입력해 주세요: \n");
scanf("%d",&arr[i][j]);
break;
default:
printf("오류 발생");
}
}
}
printf("개인 별 총점을 구하겠습니다.\n");
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
arr[i][4] += arr[i][j];
}
}
printf("과목 별 총점을 구하겠습니다.\n");
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
arr[4][i] += arr[j][i];
}
}
for(i=0; i<4; i++)
{
arr[4][4] += arr[4][i];
}
for(i=0; i<5; i++)
{
for(j=0; j<5; j++)
{
printf("%3d ", arr[i][j]);
}
printf("\n");
}
return 0;
}
The result is:
1 2 3 4 10
1 2 3 4 10
1 2 3 4 11
1 2 3 4 1874065002
5 6040476 708575245 2898508 71751423
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题是,您不是将数组元素初始化为0,因此内存中有一些提醒不重置为0,请在数组声明之后考虑执行此操作:
或在定义上{}快捷方式:
Your problem is that you aren't initializing the array elements to 0, so there are reminders in memory that not reset to 0, consider doing this after the array declaration:
or the {} shortcut at definition: