计算机应用技术II(C)期末总复习
读程序,说出运行结果:5 1、#include
float x=6.5; int y=3+3.14; printf(\ return 0; } 答案 6.50 6 2、#include
int i,a[10];
for(i=0;i<10;i++) {
a[i]=i*i-1; }
for(i=4;i>=0;i--) {
printf(\ }
return 0; } 答案15 8 3 0 -1 3、#include
int a,b; a=1; b=2; a=a+b;
b=a-b; a=a-b;
printf(\,%d\\n\return 0; } 答案 2,1 4、#include
int n;
n=4;
while(n--)
printf(\return 0; } 答案 2 0 5、#include
int i;
for(i=1; i<=10; i++) {
if(i%2) {
printf(\
}
else printf(\ } return 0; } 答案 *#*#*#*#*# 6、#include
int x,y; x=10; if (x<20) {
y=100; }
if (x>4) {
y=55/x; } else
{ y=10; }
printf(\return 0; } 答案 5 7、#include
int s,n,k,i;
scanf(\k=2*n+1; s=0;
for(i=1;i printf(\-2,s); return 0; } 例如输入3则结果为1+3+5=9 8、#include int a[3][3], i, j; for(i=0; i<3; i++) for(j=0; j<3; j++) if(i!=j) { a[i][j]=0; } else { a[i][j]=1; } for(i=0;i<3;i++) { printf(\} return 0; } 1 0 0 0 1 0 0 0 1 9、#include int i, x; x=17; for(i=2; i if(x%i==0) break; } if(i>=x) { printf(“Yes\\n”); } else { printf(\ } return 0; } 答案 yes 10、#include int a[3][3], i, j; for(i=0; i<3; i++) { for(j=0; j<3; j++) { if(i==j) {a[i][j]=1;} else {a[i][j]=0;} } } for(i=0;i<3;i++) { printf(\} return 0; } 答案1 0 0 0 1 0 0 0 1 11、#include int a,b,c; scanf(\ int min; min=a; if(b if(c float c; c=9.0123; printf(\ return 0; } 答案:求三个数中的最小值 例如输入1 2 3 结果为1 12、#include int x; char y ; x=97 ; y='b' ; printf(\,%d\return 0 ; } 答案a,98 13、#include int a,b,c; a=10; b=9; c=8; c=( a-=(b-5), (a)+(b=3) ); printf(\ return 0; } 答案9 14、#include int main() { 程序填写代码题6 答案1234,,5.5d,%.2f 15、#include int main() { int a,b,c; a=1.2; b=1; c=3; while(a>b) { a--; c--; } printf(\ 答案31、 有一份网络数据包,其中只包含字符0和1,以下程序统计其中0的个数和1的个数。 #include int main() { char ch; int onecnt=0,zerocnt=0; printf(\请输入字符串\\n\ while((ch=getchar())!='\\n') { if(ch=='1') onecnt++; else zerocnt++; } printf(\其中1的个数有%d个\\n\ printf(\的个数有%d个\\n\ return 0; } 2、 输入一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。 #include long ge,shi,qian,wan,x; scanf(\ wan=(x/10000); qian=(x/1000); shi=x/10; ge=x; if(ge==wan&&shi==qian) { printf(\} else { printf(\} return 0; } 3、 本题要求判别键盘输入字符的类别。根据输入字符的ASCII码来判别类型。由ASCII码表可知ASCII值小于32的为控制字符。 在’0’和’9’之间的为数字,在’A’和’Z’之间为大写字母, 在’a’和’z’之间为小写字母,其余则为其它字符。 #include char c; scanf(\ if(c>='0'&&c<='9') printf(\ else if(c>='A'&&c<='Z') printf(\else if(c>='a'&&c<='z') printf(\ else printf(\其它字符\\n\ return 0; } 4、 每个月有多少天。以下程序实现的功能:输入月份,输出该月份有几天。 #include int month; printf(\请输入月份:\scanf(\ switch(month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12:printf(\月份有31天\\n\ case 4: case 6: case 9: case 11: printf(\月份有30天\\n”,month);break; case 2:printf(\月份有28天\\n\default:printf(\输入的月份错误\\n\ } return 0; } 5、 编程输出如下图形 #include int line=5,i=1,j; for(i=1;i<=5;i++) { for(j=1;j<=5;j++) { if(j<=5-i ) {printf(\else { printf(\} printf(\} return 0; } 6、 从键盘输入10个整数,请判断其中有多少个负数,并求这些负数的平均值。 #include int num,i,j=0; double average = 0; for(i=0;i< 10;i++) { scanf(\ if(num<0) { average += num;j++;} } average = average/j; printf(\共有%d个负数,average = %f\\n\return 0; } 7、 以下程序的功能是:求1!+2!+…+n!的值,n的值由键盘输入。 #include int sum=0,i=1,product=1,n; printf(“输入n\\n”);