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

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

Output

输出金额,精确到分。 Sample Input 95 300 4

Sample Output 334.40 Answer

#include int main() {

int m,x,n,a; float b;

scanf(\ 0

mn)

b=0.88*a; else

b=a;

printf(\ return 0; }

9、 判断闰年

Description

输入一个正整数的年份,判断是否为闰年。 Input

输入只有一行,为一个10000以内的正整数。 Output

输出为一行。

若输入为闰年偶数则输出“Yes”,否则输出“No”。 Sample Input 2010

Sample Output No 答案

#include int main() {

int a;

scanf(\ if (a>0&&a<10000) { if (a%4==0&&a0!=0) printf(\ else if (a@0==0) printf(\ else

printf(\ } else printf(\ return 0; }

10、 水仙花数

Description

如果一个三位十进制数等于其各位数字的立方和,则称这个数为水仙花数。如:13+53+33=153。 Input

一个整数x,100<=x<=999。 Output

x是水仙花数,则输出“YES”,否则为“NO”。 Sample Input 153

Sample Output YES Answer

#include int main() {

int a,b,c,d,e; scanf(\ b=a/100;

c=(a-b*100)/10; d=(a-b*100-c*10);

e=b*b*b+c*c*c+d*d*d; if(a==e)

printf(\ else

printf(\ return 0; }

11、 三个数比较大小

Description

从键盘上输入0~100之间的三个数,按从小到大的顺序输出。 Input

输入只有一行,为三个整数。 Output

按从小到大输出这三个数。 Sample Input 15 10 20

Sample Output 10 15 20 Answer

#include int main() { int a,b,c; scanf(\ if (a>=b) { if (b>=c) printf(\ else if (a>c) printf(\ else printf(\ } else {

}

if (a>=c) printf(\ else if (b>=c) printf(\ else printf(\}

return 0;

12、 输出整数的最低两位

Description

把一个整数的最低两位打印出来,不输出整数的符号。 Input

输入为一个整数n,不会超出int类型的数据范围。 Output

输出n的最低两位数字。但是,输入的数字本身不足两位时,不应当补0。如,输入为“1”,则输出为“1”。 Sample Input -102

Sample Output 02

Answer

#include int main() { int a,b,c; scanf(\ if(a>=100) { b=a-a/100*100; printf(\ } else if(a>=0) { printf(\ } else if(a>=-99) { printf(\ } else { c=-a; b=c-c/100*100; printf(\ } return 0; }

13、判断奇偶数(填空)

Description

编写一个程序,判断读取的正整数的奇偶性,部分程序已经给出,请填上空白语句,并提交填充后的完整程序。 程序(含答案): #include int main() {

int num;

scanf(\ if (num%2==0) printf(\是一个偶数 else

printf(\是一个奇数 return 0; }

14、求分段函数的值(填空)

Description

设有分段函数如下:

给出N>0个x的值,求对应的y值并输出。

部分程序已经给出,请填充其中的空白语句,并提交填充后的完整程序。 程序(含答案): #include #include int main() {

double x,y; int i,N;

scanf(\ for (i=0;i

scanf(\ if (x<0) y=-x; else if (x<1) y=sin(2*x); else if (x<5)

y=sqrt(x*x*x+x); else

y=2*x+10; if (i==0)

printf(\ else

printf(\ }

return 0; }

15、输出是m的倍数或n的倍数、但不是m和n的公倍数的数

Description

输出1~k之间是m的倍数或n的倍数、但不是m和n的公倍数的数,其中1<=m,n

输入三个整数,依次为k、m、 n。 Output

从小到大输出符合题意的所有整数,两数之间用一个空格分开。 Sample Input 15 2 3