当前位置:文档之家› 全国计算机等级考试C语言编程题(附答案)

全国计算机等级考试C语言编程题(附答案)

全国计算机等级考试C语言编程题(附答案)
全国计算机等级考试C语言编程题(附答案)

C语言关键字速记(必考):

enum char case const unsigned do default double else extern float for goto if int long register short signed struct switch typedef union void volatile while break return continue auto

C语言的最小单位是函数。

C语言的结构有:顺序结构、循环结构和分支结构。

全国计算机等级考试c语言大题

改错题(每小题10分,2小题/套)

第1套

1.程序Cmody021.c输出如下所示图形:

*

***

*****

*******

*********

2.程序Cmody022.c的功能是求解百元买百鸡问题:

设一只公鸡2元、一只母鸡1元、一只小鸡0.5元。问一百元买一百只鸡,公鸡、母鸡、小鸡数可分别为多少?有多少种分配方案?-------------------------Cmody021.c-------------------

#include

void main()

{

/**/int i;j;/**/

for(i=1;i<=5;i++)

{

for(j=1;j<=5-i;j++)printf(" ");

/**/ for(j=1;j<=5;j++)/**/

printf("*");

printf("\n");

}

}

-------------------------Cmody022.c------------------- #include

#include

/**/int fun();/**/

{

int hen,cock,chicken,n=0;

clrscr();

for(cock=0;cock<=50;cock+=1)

for(hen=0;hen<=100;hen=hen+1)

{

chicken=2*(100-hen-2*cock);

/**/if(cock+hen+chicken=100)/**/

{

n++;

printf("%d-->hen:%d,cock:%d,chicken:%d\n",n,hen,cock,chi cken);

if(n==20)getch();

}

}

return n;

}

void main()

{

int num;

num=fun();

printf("\nThere are %d solutions.\n",num);

getch();

}

第2套

1.程序Cmody031.c的功能是:从键盘上输入两个整数,及一个运算符(+、-、*、/或%),进行相应的运算后输出运算的结果。

如输入:1+2

将输出:1+2=3

2.程序Cmody032.c的功能是:输出201-300之间的所有素数,统计总个数。

-------------------------Cmody031.c-------------------

#include

#include

void main()

{

int m,n,result,flag=0;

/**/char ch,/**/

clrscr();

printf("Input an expression:");

scanf("%d%c%d",&m,&ch,&n);

/**/switch ch/**/

{

case '+':result=m+n;break;

case '-':result=m-n;break;

case '*':result=m*n;break;

case '%':result=m%n;break;

case '/':result=m/n;break;

default:{printf("Error!\n");flag=1;}

}

if(!flag)printf("%d%c%d=%d\n",m,ch,n,result); getch();

}

-------------------------Cmody032.c------------------- #include

#include

void main()

{

int num;

printf("\n");

num=fun();

printf("\nThe total of prime is %d",num);

getch();

}

int fun()

{

int m,i,k,n=0;

for(m=201;m<=300;m++)

{

k=sqrt(m+1);

for(i=2;i<=k;i++)

/**/if(m/i==0)/**/

break;

/**/if(i==k)/**/

{

printf("%-4d",m);

n++;

if(n%10==0)printf("\n");

}

}

return n;

}

第3套

1.程序Cmody011.c的功能是:从字符串数组str1中取出ACSII 码值为偶数且下标为偶数的字符依次存放到字符串t中。

例如,若str1所指的字符串为:4AZ18c?Ge9a0z!

则t所指的字符为:4Z8z

注意:数组下标从0开始。

2.程序Cmody012.c中,函数fun(int n)的功能是:根据参数n,计算大于10的最小n个能被3整除的正整数的倒数之和。例如:-------------------------Cmody011.c-------------------

#include

#include

#include

#include

void main()

{

char str1[100],t[200];

int i,j;

/**/i=0;/**/

clrscr();

strcpy(str1,"4AZ18c?Ge9a0z!");

for(i=0;i

{

/**/if((str1[i]%2==0)&&(i%2!=0))/**/ {

t[j]=str1[i];

j++;

}

}

t[j]='\0';

printf("\nOriginal string:%s\n",str1); printf("\n Result string:%s\n",t);

}

-------------------------Cmody012.c------------------- #include

#include

#include

#include

#define M 50

double fun(int n)

{

double y=0.0;

int i,j;

j=0;

for(i=1;;i++)

{

/**/if((i<10)&&(i%3==0))/**/

{

/**/y+=1/i;/**/

j++;

}

if(j==n)break;

}

return y;

}

void main()

{

clrscr();

printf("fun(8)=%8.3lf\n",fun(8));

}

第四套

1.程序Cmody041.c,其功能是统计输入字符串中小写英文字母的个数。

如输入:abcdEFGHIJK123

输出:4

2.程序Cmody042.c,其功能是将从键盘依次输入的M个整数逆序输出。

-------------------------Cmody041.c-------------------

#include

#include

main()

{

char str1[128];

/**/int i;len,sum=0;/**/

gets(str1);

len=strlen(str1);

for(i=0;i

/**/if(str1[i]>='a'||str1[i]<='z')/**/

sum++;

}

printf("%d\n",sum);

getch();

}

-------------------------Cmody042.c------------------- #include

#include

#define M 8

main()

{

int a[M],i;

printf("Please input 8 numbers:\n");

for(i=0;i

scanf("%d",/**/a[i]/**/);

printf("Inverge order is:\n");

/**/for(i=M-1;i<=0;i--)/**/

printf("%d ",a[i]);

printf("\n");

getch();

第5套

1.程序Cmody051.c,其功能是统计输入字符串中大写英文字母的个数。

如输入:abcDEFGH123

输出:5

2.程序Cmody052.c,其功能是实现从键盘依次输入M个整数,输出其中所有的偶数。

如输入:23 62 38 45 26

输出:62 38 26

-------------------------Cmody051.c-------------------

#include

#include

main()

{

/**/char str1/**/

int i,len,sum=0;

printf("Please input a string:\n");

scanf("%s",str1);

len=strlen(str1);

for(i=0;i

{

if(str1[i]>='A'&&str1[i]<='Z')

/**/sum--;/**/

}

printf("%d\n",sum);

getch();

}

-------------------------Cmody052.c------------------- #include

#include

/**/#include M 5/**/

main()

{

int a[M],i;

printf("Please input 5 numbers:\n");

for(i=0;i

scanf("%d",&a[i]);

printf("Even numbers:\n");

for(i=0;i

/**/if(a[i]/2==0)/**/

printf("%d ",a[i]);

printf("\n");

getch();

}

第6套

1.程序Cmody061.c,其功能是将字符串中'0'-'8'的数字字符变为比它大1的数字字符,将'9'变为'0'。

如输入:abc12cd56EF89GH4

输出:abc23cd67EF90GH5

2.程序Cmody062.c,其功能是将程序中的两个字符串"ABC"、"xyz"连接在一起,并输出"ABCxyz"。

-------------------------Cmody061.c-------------------

#include

#include

main()

{

char str1[128],str2[128];

int i,len;

gets(str1);

len=strlen(str1);

/**/for(i=0;i>len;i++)/**/

{

if(str1[i]>='0'&&str1[i]<='8')

str2[i]=str1[i]+1;

else if(str1[i]=='9')

str2[i]='0';

else str2[i]=str1[i];

}

/**/str2[i]='\n';/**/

puts(str2);

getch();

}

-------------------------Cmody062.c------------------- #include

#include

void main()

{

char s1[12]="ABC",s2[]="xyz";

char *ps1=s1,*ps2;

/**/ps2=NULL;/**/

/**/while(*ps1==NULL)/**/

ps1++;

while(*ps2)*(ps1++)=*(ps2++);

printf("%s\n",s1);

getch();

}

第7套

1.程序Cmody071.c,其功能是从键盘输入三角形的三边长,求其面积,若三个边长不能构成三角形,则提示。

如输入:6 9 11

输出:26.98

2.程序Cmody072.c,其功能是求解百马百担问题。

有100匹马,驮100担货,大马驮3担,中马驮2担,两匹小马驮1担,问大、中、小马数可分别为多少?有多少种解决方案?

-------------------------Cmody071.c-------------------

#include

#include

void main()

{

float a[3],s,area;

int i;

printf("Please input 3 numbers:\n");

for(i=0;i<3;i++)

scanf("%f",/**/a[i]/**/);

/**/if(a[0]+a[1]>a[2]||a[1]+a[2]>a[0]||a[0]+a[2]>a[1])/**/ {

s=(a[0]+a[1]+a[2])/2;

area=sqrt(s*(s-a[0])*(s-a[1])*(s-a[2]));

printf("area is %.2f\n",area);

else

printf("error.\n");

getch();

}

-------------------------Cmody072.c-------------------

#include

#include

/**/void fun()/**/

{

int large,middle,small,n=0;

clrscr();

for(large=0;large<=33;large++)

for(middle=0;middle<=50;middle++)

{

small=2*(100-3*large-2*middle);

/**/if(large+middle+small=100)/**/

{

n++;

printf("%d-->large:%d,middle:%d,small:%d\n",n,large,middl e,small);

}

return n;

}

void main()

{

int num;

num=fun();

printf("\nThere are %d solutions.\n",num);

getch();

}

第8套

1.程序Cmody081.c,其功能是求一堆零件的总数(100到200之间)。

如果分成4个零件一组的若干组,则多2个零件;若分成7个零件一组,则多3个零件;若分成9个零件一组,则多5个零件。

2.程序Cmody082.c,其功能是交换连个变量的值。

如输入:Original:a=2 b=3

输出:Result:a=3 b=2

-------------------------Cmody081.c-------------------

#include

void main()

{

int i;

/**/for(i=100;i<200;i++);/**/

if((i-2)%4==0)

if(!((i-3)%7))

if(i%9==5)

printf("%d\n",/**/&i/**/);

getch();

}

-------------------------Cmody082.c------------------- #include

/**/void swap(int p1,int p2) /**/

{

int temp;

temp=*p1;

/**/p1=p2;/**/

*p2=temp;

}

void main()

{

int a,b;

printf("please input 2 numbers:\n");

scanf("%d%d",&a,&b);

printf("\nOriginal:a=%d b=%d\n",a,b);

swap(&a,&b);

printf("\nResult:a=%d b=%d\n",a,b);

getch();

}

第9套

1.程序Cmody091.C,其功能是计算1至100之间的奇数之和,偶数之和。

2.程序Cmody092.C的功能是求满足等式xyz+yzz=520的x,y,z 值(其中xyz和yzz分别表示一个三位数)。

-------Cmody091.C---------------------------------------------------------------------------

#include

void main()

{

int b,i;

/**/int a=c=0; /**/

/**/for(i=0,i<=100,i+=2)/**/

{

a+=i;

b=i+1;

c+=b;

}

printf("total of even numbers:%d\n",a);

printf("total of odd numbers:%d\n",c-101);

getch();

}

-------Cmody092.C---------------------------------------------------------------------------

#include

void main()

{

int x,y,z,i,result=520;

for(x=1;x<10;x++)

for(y=1;y<10;y++)

/**/for(z=1;z<10;z++)/**/

{

i=100*x+10*y+z+100*y+10*z+z;

/**/if(i=result) /**/

printf("x=%d,y=%d,x=%d\n",x,y,z);

}

getch();

}

相关主题
文本预览
相关文档 最新文档