第一范文网 - 专业文章范例文档资料分享平台

江苏省计算机等级考试(二级C语言)考点分析

来源:用户分享 时间:2025/7/12 20:29:16 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

{ int d;

struct node *next; }NODE;

NODE *insert(NODE *head, int x, int key) {NODE *s, *p, *q;

s=(NODE *)malloc(sizeof(NODE)); s->d=key; s->next=NULL;

if(head==NULL) {head=s; return head; }

if(head->d==x) {s->next=head; head=s; return head; } else

{ q=head; p=q->next;

while((p->d!=x)&&(p->next!=NULL)) {q=p; p=p->next; } if(p->d==x) {s->next=p; q->next=s; } else { s->next=NULL; p->next=s; } return head; } }

void print(NODE *head); { if(head==NULL) return; while(head->next!=NULL)

{ printf(“%d,”, head->d); head=head->next; } printf(“%d\\n”,head->d); } main()

{ NODE *head=NULL;

head=insert(head,0,3); print(head); head=insert(head,3,1); print(head); head=insert(head,4,5); print(head); }

答案:3 1,3 1,3,5

(4) 2005年春填空题第13题(P66-13)

以下程序运行时输出结果的第一行为________,第二行为_________,第三行为__________。 #include #include struct node { int d;

struct node *next; }

struct node *create(void)

{ struct node *head=NULL,*p, *q=NULL; int i;

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

{ p=(struct node *)malloc(sizeof(struct node)); p->d=i; p->next=NULL; if(head==NULL) head=p; else q->next=p; q=p; }

return head; }

void print(struct node *head); { if(head==NULL) return; while(head->next!=NULL)

{ printf(“%d,”, head->d); head=head->next; } printf(“%d\\n”,head->d); }

struct node *delst(struct node *head, int *n) { int count=0; struct node *p, *q, *r; p=r=head; while(p!=NULL)

{ q=p->next; while(q!=NULL)

{ if((q->d)%(p->d)==0)

{r->next=q->next; free(q); count++; q=r->next; } else {r=q; q=q->next; } }

p=p->next; }

*n=count; return head; }

void main() { int y;

struct node *head; head=creat(); print(head);

head=delst(head,&y); print(head); printf(“%d”,y); }

答案:2,3,4,5,6,7,8,9 2,3,5,7 4 五、字符串处理

(1) 2003年春填空第10题(P16-10)

以下程序运行时输出第一行是_______,第二行是________。 #include

int convert(char s1[],char s2[]) { int i=0,j,s;

char

tab[8][4]={“000”,”001”,”010”,”011”,”100”,”101”,”110”,”111”};

for(i=0,j=0; s1[i]!=’\\0’; i++,j=j+3) strcpy(&s2[j],tab[s1[i]-‘0’]);

for(i=0,s=0;i

{ char ss1[]=”15”,ss2[80]; int y;

y=convert(ss1,ss2); printf(“%d\\n%s”,y,ss2); }

分析:本程序将八进制数字组成的字符串ss1转换成二进制字符串和十进制数。 答案:13 001101

(2) 2003年春填空第12题(P17-12)

函数loop(s,m,n,str)的功能是:对字符串str中,从下标为s的字符开始的所有间隔为m的字符进行循环左移,即:str[s]←s[s+m], str[s+m]←s[s+3m], str[s+2m]←s[s+3m],?, str[s+(k-1)m]←s[s+km], str[s+km]←s[s](k为整数,下标s+km不越界),共做n次。

例如,调用loop(1,2,1,str)前后str中数据的变化情况如下: str中初始数据:A B C D E F G H I J K 移位后str数据:A D C F E H G J I B K #include #include

void loop(int s,int m,int n, char *str); main()

{char buf[81];

strcpy(buf,”ABCDEFGHIJK”); puts(buf); loop(1,2,2,buf); puts(buf); }

void loop(int s,int m,int n, char *str) {char c; int k,i,len; len=strlen(str); for(i=0; i

江苏省计算机等级考试(二级C语言)考点分析.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c3cyrh8dm9f9pugm7q9t1_3.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top