省二级上机模拟考试题目及答案(2)_第1页
省二级上机模拟考试题目及答案(2)_第2页
省二级上机模拟考试题目及答案(2)_第3页
省二级上机模拟考试题目及答案(2)_第4页
省二级上机模拟考试题目及答案(2)_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、试题一改错题以下程序的功能是输出个位数为3的最小的10个素数,如3,13,23.等。#include <stdio.h>void main() int i,j,flag,n; n=0; i=3; while(n<=10) /*$ERROR1$*/ flag=0; for(j=2;j<i;j+) if(i/j=0) /*$ERROR2$*/ flag=1; break; if(flag>=0) /*$ERROR3$*/ n=n+1; printf("%dn",i); i=i+10; 答案:(1)while(n<10) (2)if(i%j=0

2、) (3)if(flag=0)程序填空题:以下程序的功能是:输出所有的“水仙花数”,并输出“水仙花数”的个数。所谓“水仙花数”是指一个三位数,其各位数字的立方和等于该数本身。例如153是一个“水仙花数”,因为153=1*1*1+5*5*5+3*3*3.#include <stdio.h>void main() int i,a,b,c,n; n=_; /*$BLANK1$*/ for(i=101;i<=999;i+) a=i%10; b=i/10%10; c=_; /*$BLANK2$*/ if(a*a*a+b*b*b+c*c*c=i) printf("%6d&quo

3、t;,i); _; /*$BLANK3$*/ printf("nn=%dn",n);答案:(1) 0 (2)i/100 (3)n+或+n 程序编写题:计算1-500之间(即从1到500)的全部“同构数”之和。所谓“同构数”是指一个数。它出现在它的平方数的右端。如6的平方是36,6出现在36的右端,6就是同构数。输出格式: s=367#include <stdio.h>void PRINT(int s) FILE *out; printf("s=%d",s); if(out=fopen(“RESULT.DAT","w+&qu

4、ot;)!=NULL) fprintf(out,"n=%d",s); fclose(out);void main() int i; long t,s=0; for(i=1;i<=500;i+) t=i*i;if(t%10=i |t%100= =i |t%1000=i) printf(“%dt%dn”,i,i*i); s=s+i; PRINT(s); 试题二改错题:以下程序的功能是从键盘上输入一些字符,逐个把它们保存到文件abc.txt中,直到输入一个“#”为止。#include <stdio.h>void main() FILE *p1; char ch;

5、 p1=fopen("abc.txt","r"); /*$ERROR1$*/ if(p1=0) printf("cannot open filen");exit(0); ch=getchar(); while(ch!='#') fputc(ch); /*$ERROR2$*/ putchar(ch); ch=getchar(); fclose(abc.txt); /*$ERROR3$*/答案:(1)p1=fopen(“abc.txt”,”w”) (2)fputc(ch,p1) (3)fclose(p1)程序填空题:求1-

6、1/3+1/5-1/7+.+1/97-1/99的值。#include <stdio.h>void main() int i=1; double s; s=_; /*$BLANK1$*/ while(i<=50) if(_) /*$BLANK2$*/ s=s+1.0/(2*i-1); else s=s-1.0/(2*i-1); _; /*$BLANK3$*/ printf("S=%fn",s);答案:(1) 0 (2)i%2=1或i%2 (3)i+或+i 程序编写题:计算并输出Fibonacci数列中小于30000的最大一项。说明:Fibonacci数列的前

7、两项均为1,从第3项开始每一项都是其前两项的和。数列如下:1,1,2,3,5,8,13,21,.输出格式:f=2345678#include <stdio.h>void PRINT(long f) FILE *out; printf("f=%ldn",f); if(out=fopen("RESULT.DAT","w+")!=NULL) fprintf(out,"f=%ldd",f); fclose(out);void main() long f1,f2,f,i; f1=f2=1; for(i=2;i+)

8、 f=f1+f2;if (f>30000) break;f1=f2;f2=f; f=f2; PRINT(f); 试题三改错题:以下程序的功能是输入正整数n后,输出n行由小写字母a开始构成的三角形字符阵列图形(n不得大于7)。例如,输入整数4时的图形如下:a b c de f gh ij#include<stdio.h>void main()int i,j,n;char ch='a'printf("%d",&n); /*$ERROR1$*/if(n<=7) for(i=1;i<n;i+) /*$ERROR2$*/ for(

9、j=1;j<=n-i+1;j+) printf("%2c",ch); ch-; /*$ERROR3$*/ printf("n"); else printf("n is too large!n");printf("n");答案:(1)scanf(“%d”,&n) (2)for(i=1;i<=n;i+) (3) ch+程序填空题:输出以下图形1234567890#include <stdio.h>void main() int i,j; int s=0; for(i=1;_;i+) /*

10、$BLANK1$*/ for(j=1;j<=i;j+) s=s+1; printf("%d",_); /*$BLANK2$*/ printf("_"); /*$BLANK3$*/ 答案:(1)i<=4 (2)s%10 (3)n 程序编写题:编写程序,计算由数字0,1,2和3所组成不超过三位数的所有奇数之和(各位上的数字可以相同)。输出格式:s=12345#include <stdio.h>void PRINT(long s) FILE *out; printf("s=%ldn",s); if(out=fopen

11、("RESULT.DAT","w+")!=NULL) fprintf(out,"s=%ld",s); fclose(out);void main() long int s=0; int i,j,k; for(i=0;i<=3;i+) for(j=0;j<=3;j+) for(k=1;k<=3;k=k+2) s=s+i*100+j*10+k PRINT(s); 试题四改错题:以下程序的功能是输出一维数组中的最大元素及其下标。#include <stdio.h>void main() int a10=-3,1

12、,-5,4,9,0,-8,7,-6,2; int i,max,addr; max=a0; addr=1; /*$ERROR1$*/ i=1; while(i<=10) /*$ERROR2$*/ if(max<ai) max=ai; i=addr; /*$ERROR3$*/ i+; printf("max=%d,address=%dn",max,addr);答案:(1)addr=0 (2)while(i<10) (3)addr=i程序填空题:从键盘输入两个正整数,输出他们的最大公约数。#include <stdio.h>void main() i

13、nt m,n,r,t; printf("Input two number, please!n"); scanf("%d%d",_); /*$BLANK1$*/ if(m<n) t=m; m=n; _; /*$BLANK2$*/ while(n>0) r=m%n; m=n; n=r; printf("result=%dn",_); /*$BLANK3$*/答案:(1)&m,&n (2)n=t (3) m 程序编写题:根据下列公式,计算A30的值(必须使用循环)A1=1,A2=1,A3=3/(A2+A1),A4

14、=4/(A3+A2),.,A30=30/(A29+A28)输出格式:A30=7.235167#include <stdio.h>void PRINT(float f) FILE *out; printf("A30=%fn",f); if(out=fopen("K:24000123RESULT.DAT","w+")!=NULL) fprintf(out,"A30=%f",f); fclose(out);void main() float a,b,s; int i; a=1;b=1; for(i=3;i&l

15、t;=30;i+) s=i/(a+b); a=b; b=s;PRINT(s); 试题五改错题:以下程序的功能是对学生的记录数据,统计不及格的人数并输出不及格学生的信息(说明:num域代表学号,name域代表姓名,score域代表成绩)。#include <stdio.h>struct student int num; char name12; int score;void main() student stud6= 1001,"Pan Dong",48, /*$ERROR1$*/ 1002,"Zhao Hua",62, 1003,"

16、Hu Litai",93, 1004,"Zhang Li",85, 1005,"Liu Ming",58, 1006,"Xin Peng",37; int i,n=0; printf("numtnamettscoren"); i=0; while(i<6) if(score<60) /*$ERROR2$*/ printf("%dt%st%dn",studi.num,,studi.score); n-; /*$ERROR3$*/ i+; printf(&q

17、uot;n=%dn",n);答案:(1)struct student stud (2)if(studi.score<60) (3)n+程序填空题:将3*3的矩阵值(从键盘输入)存于数组a中,计算并输出该矩阵两条对角线元素的总和s。#include <stdio.h>void main() int a33, i,j,s=0; printf("Input array:n"); for (i=0;i<3;i+) for(j=0;j<3;j+) scanf("%d",_); /*$BLANK1$*/ for (i=0;i&

18、lt;3;i+) for(j=0;j<3;j+) if(i=j)_ (i+j=2) /*$BLANK2$*/ s+=_; /*$BLANK3$*/ printf("s=%dn",s); 答案:(1)&aij (2) | (3) aij 程序编写题:根据下式求s的值(要求使用循环实现):s=1-2/3+3/5-4/7+5/9-6/11+.+49/97输出格式:s=1.23456#include <stdio.h>void PRINT(double s) FILE *out; printf("s=%.4fn",s); if(out=

19、fopen("RESULT.DAT","w+")!=NULL) fprintf(out,"s=%.4f",s); fclose(out);void main() int i,flag=1; double s=0; for(i=1;i<=49;i+) s+=flag*1.0*i/(2*i-1); flag=-flag; PRINT(s); 试题六改错题:以下程序的功能是输入5名学生4门课的成绩,输出每门课的最高分。#include <stdio.h>#define N 5#define M 4void main() i

20、nt i, j;float score, firstscore,max;i=1;while(i<M) /*$ERROR1$*/printf("n Please input score of course no %d:",i);scanf("%f", firstscore );/*$ERROR2$*/max = firstscore;for(j=2;j<=N; j+) scanf("%f" , &score);if(score>max) score =max; /*$ERROR3$*/printf("

21、n The max score of course no %d is: %f", i, max);i+;答案:(1)while(i<=M) (2)scanf(“%f”,&firstscore) (3)max=score程序填空题:从键盘输入一个整数作为月份,输出其对应的英文季节单词。若输入的整数在1到12之外,则输出“Error!”。#include <stdio.h>void main() int n; printf("Input n:"); scanf("%d",_); /*$BLANK1$*/ switch(n)

22、 case 3: case 4: case 5:printf("Springn");break; case 6: case 7: case 8:printf("Summern"); _; /*$BLANK2$*/ case 9: case 10: case 11:printf("Autumnn"); break; case 1: case 2: case 12:printf("Wintern"); break; _:printf("Error!n"); /*$BLANK3$*/ 答案:(1)&a

23、mp;n (2)break (3)default 程序编写题:计算1+2+3+4+.+n<2000的最大的n的值(要求使用循环实现)输出格式:n=23456#include <stdio.h>void PRINT(int n) FILE *out; printf("n=%dn",n); if(out=fopen("RESULT.DAT","w+")!=NULL) fprintf(out,"n=%dd",n); fclose(out);void main() int n=0,s=0; while(s

24、<2000) s=s+(+n); n-; PRINT(n); 试题七改错题:以下程序的功能是通过指针操作,将由八进制数字组成的字符串“77777”转换为对应的十进制整数。#include <stdio.h>void main() char str6="77777",p; /*$ERROR1$*/ int n,t; n=1; /*$ERROR2$*/ p=str; while(*p!=0) t=*p-'0' n=n*8+t; p-; /*$ERROR3$*/ printf("n%s is convered to integer nu

25、mber: %dn",str,n);答案:char str6=”77777”,*p; (2)n=0; (3)p+;程序填空题:以下程序是将从键盘输入的字符串逆序存放,然后输出,(如:输入ABCD1A,输出A1DCBA)。#include<stdio.h>#include<string.h>main() char s81,t; int i,j,n; gets(s); n=strlen(s); _; /*$BLANK1$*/ j=n-1; while(_) /*$BLANK2$*/ t=si; si=sj; sj=t; i+; _; /*$BLANK3$*/ pr

26、intf("%s",s); 答案:(1)i=0 (2)i<j (3)j- - 程序编写题:统计并输出21世纪(2000年到2099年)闰年的个数。符合以下条件之一即为闰年: 是400的倍数,如2000年 是4的倍数但不是100的倍数,如2012年。输出格式:n=16#include <stdio.h>void PRINT(int n) FILE *out; printf("n=%dn",n); if(out=fopen("RESULT.DAT","w+")!=NULL) fprintf(out,&

27、quot;n=%dg",n); fclose(out);void main() int n,i; n=0; for(i=2000;i<2100;i+) if(i%400= =0 |(i%4= =0 && i%100!=0) n+; PRINT(n); 试题八改错题:下列程序的功能是:输入一个字符串,在指定的位置插入字符s。(插入的字符从键盘输入,且假设位置在字符串的长度以内)#include <stdio.h>#include<string.h>main() char a80; int i,j,k; scanf("%s"

28、;,a); scanf("%d",i); /*$ERROR1$*/ k=strlen(a); j=k; while(j>=i) aj+1=aj; j+; /*$ERROR2$*/ aj='s' ; /*$ERROR3$*/ printf("%s",a); 答案:(1)scanf(“%d”,&i); (2)j-; (3)ai=s;程序填空题:删除已知字符串s中的所有ASCII码值为奇数的字符,形成新的字符串并输出。#include <stdio.h>void main() int n=0,i; char s=&qu

29、ot;asdg dfbsfj120mjd456m6m7n987nhyr" for(i=0;si!=_;i+) /*$BLANK1$*/ if(si%2_0) /*$BLANK2$*/ sn+=si; sn=_; /*$BLANK3$*/ puts(s);答案:(1) 程序编写题:根据下式求s的值(求前20项之和)s=1/(1+2+3)-1/(2+3+4)+1/(3+4+5)-i/(4+5+6)+.+1/(19+20+21)-1/(20+21+22)输出格式:s=0.1234#include <stdio.h>void PRINT(double s) FILE *out;

30、printf("s=%.4fn",s); if(out=fopen(“RESULT.DAT","w+")!=NULL) fprintf(out,"s=%.4f",s); fclose(out);void main() int i,flag=1; float s=0; for(i=1;i<=20;i+) s=s+1.0/(3*(i+1)*flag; flag=-flag;PRINT(s); 试题九改错题:以下程序中,函数fun的功能是:按以下递归公式求函数值。fun(n)=0 (n<1或n>100)fun(n)=8 (n=1)fun(n)=fun(n-1)+3 (n>1并且n<=100)#include <stdio.h>int fun(n) /*$ERROR1$*

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论