c二级模拟程序题.docx
- 文档编号:24591031
- 上传时间:2023-05-29
- 格式:DOCX
- 页数:20
- 大小:17.85KB
c二级模拟程序题.docx
《c二级模拟程序题.docx》由会员分享,可在线阅读,更多相关《c二级模拟程序题.docx(20页珍藏版)》请在冰豆网上搜索。
c二级模拟程序题
新疆维吾尔自治区二级C语言上机题库
(一)
#include
voidfibonacci(intf[])
{inti;
/********fillintheblanks********/
for(i=____;i<20;i++)
/********fillintheblanks********/
f[i]=_____;
}
main()
{intf[20]={1,1},i;
fibonacci(f);
printf("\n菲的前20项:
");
for(i=0;i<20;i++)
{if(i%5==0)
printf("\n");
/********fillintheblanks********/
printf("%12d",______);
}
}
菲的前20项:
11235
813213455
89144233377610
9871597258441816765Pressanykeytocon
tinue
#include
voidtrans(inta[2][3],intb[3][2])
{/********Error********/
inti;
for(i=0;i<2;i++)
for(j=0;j<3;j++)
/********Error********/
a[j][i]=b[i][j];
}
main()
{inta[2][3]={{1,2,3},{4,5,6}},b[3][2],i,j;
printf("数组a:
\n");
for(i=0;i<2;i++)
{for(j=0;j<3;j++)
printf("%5d",a[i][j]);
printf("\n");
}
trans(a,b);
printf("数组b:
\n");
for(i=0;i<3;i++)
{for(j=0;j<2;j++)
printf("%5d",b[i][j]);
printf("\n");
}
}
数组a:
123
456
数组b:
14
25
36
Pressanykeytocontinue
#include
intsuffix(inta[],intn)
{
}
main()
{voidCHECK();
intarr[10]={56,178,6,123,87,243,161,124,78,143},k;
k=suffix(arr,10);
printf("数组arr的最大为:
arr[%d]=%d\n",k,arr[k]);
}
数组arr的最大为:
arr[5]=243
Pressanykeytocontinue
#include
/********fillintheblanks********/
doublesum(int____)
{inti;
doubley,d;
/********fillintheblanks********/
y=_____;
for(i=100;i<=m;i+=100)
{d=(double)i*(double)i;
y+=1.0/d;
}
/********fillintheblanks********/
return(______);
}
main()
{intn=2000;
printf("\ntheresultis:
%lf\n",sum(n));
}
theresultis:
0.000160
Pressanykeytocontinue
#include
/********Error********/
intcomp(intx,y)
{intflag;
if(x>y)
flag=1;
/********Error********/
elseif(x=y)
flag=0;
elseflag=-1;
return(flag);
}
main()
{inti,n=0,m=0,k=0;
inta[10]={5,-23,5,21,6,18,9,12,23,7};
intb[10]={6,-9,64,23,-52,0,9,8,-35,12};
printf("数组a:
\n");
for(i=0;i<10;i++)
printf("%4d",a[i]);
printf("\n");
printf("数组b:
\n");
for(i=0;i<10;i++)
printf("%4d",b[i]);
printf("\n");
for(i=0;i<10;i++)
{if(comp(a[i],b[i])==1)
n=n+1;
elseif(comp(a[i],b[i])==0)
m=m+1;
elsek=k+1;
}
printf("a[i]>b[i]%2d次\na[i]=b[i]%2d次\na[i]
}数组a:
5-23521618912237
数组b:
6-96423-52098-3512
a[i]>b[i]4次
a[i]=b[i]1次
a[i]
Pressanykeytocontinue
#include
intfun(inta[],intn)
{
}
main()
{voidCHECK();
intarr[20],i,k,n;
n=1000;
k=fun(arr,n);
for(i=0;i printf("%4d",arr[i]); } 77154231308385462539616693770847924Pressanykeytocontinue #include #defineN5 floatcount(inta[N][N]) { } main() {voidCHECK(); intarr[N][N]={{0,1,2,7,9},{1,9,7,4,5},{2,3,8,3,1},{4,5,6,8,2},{5,9,1,4,1}}; printf("二arr的平值: %f\n",count(arr)); } #include longfibonacci(intn) {longa=1,b=1,c=1,d; inti; /********fillintheblanks********/ for(i=_____;i<=n;i++) {/********fillintheblanks********/ d=______; a=b; b=c; c=d; } /********fillintheblanks********/ return______; } main() {intn=20; printf("广义菲%d项: %ld\n",n,fibonacci(n)); } #include voidsort(inta[],intn) {inti,j,t; for(j=0;j for(i=0;i if(a[i]>a[i+1]) {t=a[i]; /********Error********/ a[i]=a[j]; /********Error********/ a[i]=t; } } main() {intk,a[10]={6,-9,78,23,-12,0,9,8,-3,12}; printf("数组a: \n"); for(k=0;k<10;k++) printf("%d",a[k]); sort(a,10); printf("\n从小到大排序: \n"); for(k=0;k<10;k++) printf("%d",a[k]); printf("\n"); } 数组a: 6-97823-12098-312 从小到大排序: -12-9-30689122378 Pressanykeytocontinue #include longsum(intn) { } main() {voidCHECK(); intn=1800; /*clrscr();*/ printf("1到%d之间,能被3和7整除的和为: %ld\n",n,sum(n)); } 1到1800之间,能被3和7整除的和为: 76755 Pressanykeytocontinue #include intcount(charstr[],charsubstr[]) {inti,j,k,num=0; /********fillintheblanks********/ for(i=0;str[i]! =____;i++) for(j=i,k=0;substr[k]==str[j];k++,j++) /********fillintheblanks********/ if(_____! ='\0') {num++; break; } /********fillintheblanks********/ return(_____); } main() {charstr[80],substr[80]; printf("Inputastring: "); gets(str); printf("Inputasubstring: "); gets(substr); printf("Theresultis: %d\n",count(str,substr)); } Inputastring: ThisisaCProgram, Inputasubstring: is, Theresultis: 2 Pressanykeytocontinue #include voidfun(inta[3][3],floatb[3]) {inti,j; for(i=0;i<3;i++) {for(j=0;j<3;j++) /********Error********/ b[j]=a[i][j]; } for(i=0;i<3;i++) /********Error********/ b[i]=3; } main() {inta[3][3]={{1,2,3},{4,5,6},{7,8,9}},i; floatb[3]={0,0,0}; fun(a,b); for(i=0;i<3;i++) printf("%4.1f",b[i]); printf("\n"); } 4.05.06.0 Pressanykeytocontinue #include min_value(intarray[][4]) {inti,j,min; min=array[0][0]; for(i=0;i<3;i++) /********fillintheblanks********/ for(j=0;j<___;j++) if(array[i][j] /********fillintheblanks********/ ____=array[i][j]; /********fillintheblanks********/ return(____); } main() {inta[3][4]={{-11,23,15,37},{29,48,6,-8},{15,17,34,12}}; printf("矩的最小值=%d\n",min_value(a)); } 矩的最小值=-11 Pressanykeytocontinue #include floataverage(floatarray[],intn) {inti; floataver,sum=array[0]; /********fillintheblanks********/ for(i=1;i<____;i++) sum=sum+array[i]; /********fillintheblanks********/ aver=____; /********fillintheblanks********/ return(_____); } main() {floatscore_1[5]={98.5,97,91.5,60,55}; floatscore_2[10]={67.5,89.5,99,69.5,77,89.5,76.5,54,60,99.5}; printf("班级A学生成绩的平均值=%6.2f\n",average(score_1,5)); printf("班级A学生成绩的平均值=%6.2f\n",average(score_2,10)); } 班级A学生成绩的平均值=80.40 班级A学生成绩的平均值=78.20 Pressanykeytocontinue #include /********Error********/ voidchange(chars) {inti,k; k=0; /********Error********/ for(i=0;s[i]='\0';i++) if(k) {if(s[i]=='') k=0; } elseif(s[i]! ='') {k=1; s[i]=toupper(s[i]); } } main() {charstr[80]; printf("\nPleaseenteranenglishtextline: "); gets(str); printf("Beforechanging: \n%s",str); change(str); printf("\nAfterchenging: \n%s\n",str); } Pleaseenteranenglishtextline: Iamastudenttotaketheexamination. Beforechanging: Iamastudenttotaketheexamination. Afterchenging: IAmAStudentToTakeTheExamination. Pressanykeytocontinue #include floatcount(intn) { } main() {voidCHECK(); intn=100; /*clarce();*/ printf("11111\n"); printf("1--+---+--……-=%f\n",count(n)); printf("2345%d\n",n); } 11111 1--+---+--……-=0.688172 2345100 Pressanykeytocontinue #include /********fillintheblanks********/ doublesum(int____) {inta,b,c,k; doubles; /********fillintheblanks********/ s=_____; a=2; b=1; for(k=1;k<=n;k++) {s=s+(double)a/b; c=a; /********fillintheblanks********/ a=_____; b=c; } returns; } main() {intn=5; printf("\nThevalueoffunctionsumis: %f\n",sum(n)); } Thevalueoffunctionsumis: 8.391667 Pressanykeytocontinue #include /********Error********/ doublecount(doublea,b) {doublec; /********Error********/ c=abs(a+b); returnc; } main() {doublex,y,z; printf("Enterx,y: "); scanf("%lf,%lf",&x,&y); z=count(x,y); printf("z=%f\n",z); } Enterx,y: 23,2 z=1077478015.000000 #include longcount(intn) { } main(); {voidCHECK(); intn; /*clrscr()*/ printf("InputN: "); scanf("%d",&n); printf("%d! =%ld",n,count(n)); getch(); CHECK(); } #include #defineM5 /********fillintheblanks********/ intcount(intn,int_____) {inti,sum=0; for(i=0;i sum+=a[i][i]; /********fillintheblanks********/ return(______); } main() {intarr[M][M]={{1,2,3,4,5},{4,3,2,1,0},{6,7,8,9,0},{9,8,7,6,5},{3,4,5,6,7}}; inti,j; printf("\n%d×%d数组元素: \n",M,M); for(i=0;i {for(j=0;j /********fillintheblanks********/ printf("%4d",______); printf("\n"); } printf("主对角线之和: %d",count(M,arr)); } 5×5数组元素: 12345 43210 67890 98765 34567 主对角线之和: 25Pressanykeytocontinue #include voidinvert(charstr[],intn) { } main() {voidCHECK(); chars[10]="abcd"; intn=4; printf("处理前字符串=%s\n",s); invert(s,n); printf("处理后字符串=%s\n",s); } 处理前字符串=abcd 处理后字符串=dcba Pressanykeytocontinue #include intupper,lower,digit,space,other; /********Error********/ count(charstr) {inti=0; while(str[i]! ='\n') {if(str[i]>='A')&&(str[i]<='Z')) upper++; elseif((str[i]>='a')&&(str[i]<='z')) lower++; /********Error********/ elseif(str[i]='') space++; elseif((str[i]>='0')&&(str[i]<='9')) digit++; else other++; i++; } } main() {inti=0; chars[80]; printf("\n请输入一行字符: "); while((s[i]=getchar())! ='\n') i++; upper=lower=digit=space=other=0; count(s); printf("其中,大写字母个数: %d,小写字母个数: %d,空格子数: %d,数字个数: %d, 其他字符个数: %d",upper,lower,digit,space,other); } #include /********Error********/ voidinverse(charstr) {inti,j; chart; for(i=0,j=strlen(str);i {t=str[i]; /********Error********/ str[i]=str[j]; str[j-1]=t; } } main() {charstr[80]; inti=0; printf("\n请输入一个字符串: "); while((str[i]=getchar())! ='\n') i++; str[i]='\0'; inverse(str); printf("此字符串的逆序为: %s",str); } 请输入一个字符串: sjdlki 此字符串的逆序为: ikldjsPressanykeytocontinue
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 二级 模拟 程序
![提示](https://static.bdocx.com/images/bang_tan.gif)