C语言练习题(山东科技大学吐血整理) 联系客服

发布时间 : 星期六 文章C语言练习题(山东科技大学吐血整理)更新完毕开始阅读fe3c638a71fe910ef12df858

scanf(\ max=array[0]; numOfMax=0; maxIndex[numOfMax++]=0; for (i=1; i

if (max

max=array[i]; numOfMax=0; maxIndex[numOfMax++]=i; }

else if (array[i]==max) {

maxIndex[numOfMax++]=i; } }

printf(\ printf(\ for (i=1;i

return 0; }

34、求矩阵的每行之和(编程题)

Description

编写一个程序,求一个矩阵的每行值的和。设矩阵的所有元素都是整数,而且每行的和不超过int类型的表示范围。 Input

输入为多行。第一行K>0,表示有K个测试用例。

之后K个测试用例中,首先是两个整数0

输出有K行,每个测试用例的结果占一行。每行的格式为: case i:d1 d2 ... dj

其中i表示测试用例的编号(从1开始),d1、d2、....、dj表示相应测试用例的各行的和,两两之间用空格隔开。 Sample Input 4 3 3 1 2 3 1 2 3 1 2 3 2 3 1 1 1 1 1 1 1 1 1 5 1 3 4 5 6 7

Sample Output case 1:6 6 6 case 2:3 3 case 3:1

case 4:3 4 5 6 7 Answer

#include int main() { int K,i,j,k,m,n,r[100],sum[100][100],a[100][100]; scanf(\ for(k=0;k

for(i=0;i

35、 一维数组的逆序(编程题)

Description

编程,实现对一个一维数组的逆序,即将数组的元素反转。 Input

输入分多行,第一行是N>0,表示有N个用例。

每个用例的输入有1行或2行,其中第一行是0<=M<=1000,表示该数组有M个整数。如果M>0,则第二行包含M个整数,两两之间用空格隔开;如果M=0,则该用例没有第二行输入。 Output

输出为N行,每行与上述输入一一对应,分别是对应用例的逆序。输出格式为: case i:d1 d2 ...

其中i表示用例编号(从1开始),d1、d2等是数组逆序后的结果,两两之间用空格隔开。如果该用例不包含任何输入,即:M=0,则仅输出: case i:

Sample Input 3 10

10 9 8 7 6 5 4 3 2 1 0 5

1 2 3 4 5

Sample Output

case 1:1 2 3 4 5 6 7 8 9 10 case 2:

case 3:5 4 3 2 1 Answer

#include int main() { int N,M[10000],a[100][1001],i,j; scanf(\ for(i=0;i0;j--) printf(\ printf(\ printf(\ } else printf(\ } return 0; }

36、 结构体的使用(编程题)

Description

设有结构体定义如下: typedef struct Student {char major[50];//专业 char name[50];//姓名

int score[3];//3门课程的成绩 } STU;

编写一个子函数,输出每个学生的总分,函数原型如下: void printInfo(STU students[],int num);

其中students[]是由num个STU类型的结构体组成的数组。 输出格式见下。

注意:主函数已经给出,提交时需提交以下内容:上述结构体STU的定义(直接复制上就可以,要放在头文件包含命令之后)、必要的头文件包含命令以及printInfo函数的代码。 Input

输入为多行。第一行N>0表示有N个学生的信息。之后有N行,每一行包含5个部分,分别表示每位学生的专业、姓名和3门课程的成绩,两两之间用空格隔开。成绩为正整数。 Output

输出为N行,每一行为一名学生的信息,格式为: major,name:totalSocre.

其中major表示学生的专业,name表示学生的姓名,totalScore表示该生的总分。所有的标点符号均为半角字符。

Sample Input 3

Computer Tom 100 98 89 Information Jack 98 89 87 Management Mary 89 89 89 Sample Output Computer,Tom:287. Information,Jack:274. Management,Mary:267. Answer

#include typedef struct Student {

char major[50]; char name[50]; int score[3]; } STU;

void printInfo(STU students[],int num) { int i;

for(i=0;i

printf(%udents[i].score[2]); printf(\} }

int main() {

int i,N;

scanf(\ STU stus[N]; getchar();

for (i=0;i

scanf(\

scanf(\ }

printInfo(stus,N); return 0; }