急求max187的C语言程序(在硬件上已经试验过的)不胜感激!
答案:2 悬赏:0 手机版
解决时间 2021-04-11 21:31
- 提问者网友:聂風
- 2021-04-11 06:17
急求max187的C语言程序(在硬件上已经试验过的)不胜感激!
最佳答案
- 五星知识达人网友:迟山
- 2021-04-11 07:26
从网站上找的:
#include
#include
#include
using namespace std;
#define NUM 50
int main()
{
int scores[NUM][4];
char names[NUM][30];
char nm[30];
int i, j, sc[4];
cout << "输入学生姓名、高数、英语和C语言成绩:"<< endl;
for (i = 0; i < NUM; ++i)
{
cin >> names[i] >> scores[i][0] >> scores[i][1] >> scores[i][2];
scores[i][3] = scores[i][0] + scores[i][1] + scores[i][2];
}
for (i = 1; i < NUM; ++i)
{
for (j = NUM - 1; j >= i; --j)
{
if (scores[j][3] > scores[j-1][3])
{
strcpy(nm, names[j]);
strcpy(names[j], names[j-1]);
strcpy(names[j-1], nm);
int sz = sizeof(int) * 4;
memcpy(sc, scores[j], sz);
memcpy(scores[j], scores[j-1], sz);
memcpy(scores[j-1], sc, sz);
}
}
}
for (i = 0; i < NUM; ++i)
cout << i+1 << ". " << names[i] << "\t总分: " << scores[i][3] << endl;
return 0;
}
#include
#include
#include
using namespace std;
#define NUM 50
int main()
{
int scores[NUM][4];
char names[NUM][30];
char nm[30];
int i, j, sc[4];
cout << "输入学生姓名、高数、英语和C语言成绩:"<< endl;
for (i = 0; i < NUM; ++i)
{
cin >> names[i] >> scores[i][0] >> scores[i][1] >> scores[i][2];
scores[i][3] = scores[i][0] + scores[i][1] + scores[i][2];
}
for (i = 1; i < NUM; ++i)
{
for (j = NUM - 1; j >= i; --j)
{
if (scores[j][3] > scores[j-1][3])
{
strcpy(nm, names[j]);
strcpy(names[j], names[j-1]);
strcpy(names[j-1], nm);
int sz = sizeof(int) * 4;
memcpy(sc, scores[j], sz);
memcpy(scores[j], scores[j-1], sz);
memcpy(scores[j-1], sc, sz);
}
}
}
for (i = 0; i < NUM; ++i)
cout << i+1 << ". " << names[i] << "\t总分: " << scores[i][3] << endl;
return 0;
}
全部回答
- 1楼网友:三千妖杀
- 2021-04-11 08:46
从网站上找的:
#include
#include
#include
using namespace std;
#define num 50
int main()
{
int scores[num][4];
char names[num][30];
char nm[30];
int i, j, sc[4];
cout << "输入学生姓名、高数、英语和c语言成绩:"<< endl;
for (i = 0; i < num; ++i)
{
cin >> names[i] >> scores[i][0] >> scores[i][1] >> scores[i][2];
scores[i][3] = scores[i][0] + scores[i][1] + scores[i][2];
}
for (i = 1; i < num; ++i)
{
for (j = num - 1; j >= i; --j)
{
if (scores[j][3] > scores[j-1][3])
{
strcpy(nm, names[j]);
strcpy(names[j], names[j-1]);
strcpy(names[j-1], nm);
int sz = sizeof(int) * 4;
memcpy(sc, scores[j], sz);
memcpy(scores[j], scores[j-1], sz);
memcpy(scores[j-1], sc, sz);
}
}
}
for (i = 0; i < num; ++i)
cout << i+1 << ". " << names[i] << "\t总分: " << scores[i][3] << endl;
return 0;
}
希望对你有帮助 需要自己改动
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯