最新春江苏省计算机二级c语言试题与答案(笔试)

发布时间 : 星期二 文章最新春江苏省计算机二级c语言试题与答案(笔试)更新完毕开始阅读

精品文档

start++,end--; }

for(i=O;i

10.以下程序运行时输出结果中第一行是(11),第二行是(12)。 #include

void fun(int x,int P[],int *n) { int i,j=O;

for(i=1;i<=x/2;i++) if(x%i==0)p[j++]=i; *n=j: }

void main() {int x,a[10],n,i; fun(27,a,&n); for(i=0;i

printf(\ printf(\ }

11.以下程序运行时输出结果是(11) 。 #include #include int count(char s[]) { int i=0;

if(s[i]=='\\0') return 0; while(isalpha(s[i]))i++;

while(!isalpha(s[i])&&s[i]!='\\0')i++; return 1+count(&s[i]); }

void main()

{char line[]=\ world , one dream.\ printf(\ } .

12.以下程序运行时输出结果中第一行是 (14) #include

int fun(char *a,char *b) {int m=0,n=0:

while(*(a+m)!='\\0')m++; while(b[n])

{ *(a+m)=b[n];m++;n++; } *(a+m)='\\0'; return m; 精品文档

,第二行是(15) 精品文档 }

void main()

{char s1[20]=\ printf(\ puts(s1); }

13.以下程序运行时输出结果中第-行是 (16) ,第二行是 (17) ,第三行是( 18 ) #include

typedef struct{int x;int y;}S; void fun(S pp[],int n) {int i,j,k;S t;

for(i=0;i

for(j=i+1;j

if((pp[j].x

{t=pp[i];pp[i]=pp[k];pp[k]=t;} } }

void main()

{S a[5]={{3,2},{3,1},{1,2},{2,4},{2,3}}; int i,n=5; fun(a,n);

for(i=0;i

printf(\ } . ●完善程序

14?以下程序求一组整数的最大公约数。试完善程序以达到要求的功能。 #include

int gcd(int a,int b) i {int r;

while(_____(19)_______)

{r=a%b;a=b;(_____20_____);} return a; }

void main()

{int x,i,a[6]={12,56,48,32,16,24}; x= (___21_____) ; for(i=1;i<6;i++)

x=gcd(___(22)_____,a[i]); printf(\ for(i=1;i<5;i++) printf(\

printf(\ } 精品文档

精品文档

15.以下程序完成两个长正整数的加法运算并输出计算结果。函数add模拟手工加法运算的过程,将a和b指向的数组中存储的两个以字符串形式表示的n位正整数相加,并将运算结果以字符串形式保存到c指向的数组中。main函数中pl和p2数组分别存放被加数字符串和加数字符串,p3数组存放运算结果字符串。若p1中的字符串为\、p2中的字符串为\调用add函数后p3得到的是以字符串表示的这两个整数相加的结果\。试完善程序以达到要求的功能。 #include \ #include \

void add(char a[],char b[],char c[],__(23)____) {int i,k;

c[n]='\\0';k=0; for(i=n-1;i>=0;i--)

{c[i]=(a[i]-'0')+(b[i]-'0')+k; k=______(24)______; c[i]=c[i]+'0'; } if(k)

{for(i=n+1;i>0;i--) c[i]=___(25)____; c[i]=k+'0'; } }

void main()

{char p1[80]=\ int i,x=strlen(p1),y=strlen(p2); if(x

{ for(i=x;i>=0;i--)

{p1[i+y-x]=p1[i];p1[i]='0';} _____(26)______; }

if(x>y)

for(i=y;i>=0;i--)

{p2[i+x-y]=p2[i];p2[i]='0';} add(p1,p2,p3,x); puts(p3); }

16.以下程序创建-个链表并实现数据统计功能。函数WORD *create(char a[][20], int n)创建-个包含n个结点的单向链表,结点数据来自a指向的数组中存储的n个单词(字符串)。函数void count(WORD *h)统计h指向的单向链表中不同单词各自出现的次数,将统计结果保存到局部数组c中并输出。程序运行时输出结果为\ green:2 blue:3\试完善程序以达到要求的功能。 #include \ #include \ #include \ typedef struct w {char word[20]; struct w *next: }WORD; 精品文档

精品文档

WORD *create(char a[][20],int n) {WORD *p1,*p2,*h=0;int i; for(i=0;i

{p1=(WORD *)malloc(sizeof(WORD)); strcpy(___(27)___,a[i]); if(h==O) h=p2=p1: else

{p2->next=p1;p2=pl;} }

p2->next=_____(28)____; return h; }

void count(WORD *h) { struct

{char word[20]; int num; }c[6]={0}; int m=0,i; while(h) {if(m==0)

{strcpy(c[0].word,h->word); c[0].num=1;m++; } else

{for(i=0;i

if(strcmp(c[i].word,h->word)==0 { ______(29)_____ ; break; }

if(i>=m)

{strcpy(c[m].word,h->word); c[m++].num=1; } }

____(30)_____; }

for(i=0;i

printf(\:%d\ }

void main()

{char words[6][20]={\ WORD *head=0: head=create(words,6);

count(head); 精品文档

精品文档 }

第一部分 计算机基础知识

1.D 2.B 3.B 4.D 5.B 6.D 7.A 8.C 9.D 10.A 11.B 12.A 13.A 14.C 15.C 16.B 17.C 18.A 19.A 20.C

第二部分 C程序设计

21.B 22.D 23.C 24.A 25. A 26.C 27.D 28.B 29.B 30.D

二:填空

(1)main函数定义 (2)32767 (3)3.15 (4) 6 (5)3.3 (6)2 3 (8)7

(9)11111 (10)12321 (11)1 3 9 (12)3 (13)4 (14)5 (18)2,4 (19)b或b!=0

(20)b=r (21)a[0] (22)x (23)int n (24)c[i]/10 (27)p1->word

(28)0或NULL (29)c[i].num++ (30)h=h->next

精品文档

5 6 (7)x=18, y=27 , z=18 (15)yesno (16)1,2 (17)2,3 (25)c[i-1] (26)x=y

联系合同范文客服:xxxxx#qq.com(#替换为@)