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

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

Sample Output 2 3 4 8 9 10 14 15 Answer

#include int main() { int k,m,n,a,i=1; scanf(\ if(m

16、A+B ProblemT

Description

计算a+b,0<=a,b<1000。 Input

输入有多对整数a和b组成,每对a和b占一行,a,b用空格分开。 Output

每行输出一个a+b的值,顺序与输入对应。 Sample Input 1 2 10 20

Sample Output 3 30

Answer

#include int main() { int a,b; while(scanf(\ { printf(\ } return 0; }

17、A+B Problem (II) : Input/Output Pratice

Description

计算a+b,0<=a,b<1000。 Input

输入的第一行是一个整数N,后面有N对整数a和b,每对a和b占一行,a,b用空格分开。 Output

每行输出一个a+b的和,顺序与输入对应。 Sample Input 2 1 2 10 20

Sample Output 3 30

Answer

#include int main() { int a[1000],b[1000],N,i; scanf(\ for(i=1;i<=N;i++) scanf(\ for(i=1;i<=N;i++) printf(\ return 0; }

18、成绩的等级

Description

把百分制的考试成绩转换成五级制的成绩: 90~100:Excellent 80~89:Good 70~79:Average 60~69:Pass 0~59:Failing

不在0~100之间的输入是非法数据,输出“Error”。 Input

输入多行,每行一个整数。 Output

输入所对应的成绩等级。 Sample Input -1 81 92 35 68 72 100

Sample Output Error Good Excellent Failing Pass Average Excellent Answer

#include int main() {

int score; while(scanf(\ { if (score<0||score>100) printf(\ else {

switch (score/10) { case 0: case 1: case 2: case 3: case 4: case 5:printf(\ case 6:printf(\ case 7:printf(\ case 8:printf(\ case 9: case 10:printf(\ } } }

return 0; }

19、n个数的最大值和最小值

Description

找出n个数中最大的数和最小的数,并将它们的值输出出来。 Input

输入为n+1个整数,都在int类型范围内。这些数可能用若干空格或者换行符分隔开。 输入的第1个数为n,表示后续有n个数输入。从输入的第2个数开始,求出直到第n+1个数中最大的数和最小的数。 Output

输出为两行,格式见sample。 Sample Input 3 0 1 -1

Sample Output

The maximum number is 1. The minimum number is -1. Answer

#include int main() {

int n,i,max,min; scanf(\ int a[n];

for(i=0; i

scanf(\ max=a[0]; min=a[0];

for(i=0; i

if(maxa[i]) min=a[i]; }

printf(\ printf(\ return 0; }

20、字符加密

Description

Tom和Jack是密码学爱好者,他们在聊天时经常使用一些暗语。他们使用的一种最简单的暗语是:将要说的每句话里面的英文字母变成这个字母之后的某个字母。现在要求你写一个程序,将一个字母变成它之后的某个字母。 Input

输入有2个:一个大写字母c和一个正整数d(0

输出字母c之后的第d个字母。大小写与c一致。如果c之后的某个字母已经超出'Z',则再从字母'A'开始计数。

如:c='A',d=3,则输出应为:D。 若:c='Y',d=3,则输出应为:B。 Sample Input A 3

Sample Output D

Answer

#include void main() { int d,x; char c; scanf(\ scanf(\ x=c+d; c=c+d; x<=90?printf(\ }

21、求100以内的素数

Description

素数是只能被1和自身整除的正整数,根据数学定义1不是素数。素数也叫质数。 Input

输入为两个整数m和n,满足0<=m<=n<=100。 Output

从大到小输出m~n之间的所有素数,一个素数一行。如果m~n之间没有素数,则不输出任何数。

输出的所有数在两行“=====”之间。 Sample Input 2 12

Sample Output ===== 11 7 5 3 2

===== Answer

#include #include int main() {