二级c语言题库(编辑修改稿)内容摘要:

(\nOutput from head:\n)。 outlist(head)。 printf(\nOutput from tail: \n)。 while (headnext != NULL){ fun(head)。 printf(\n\n)。 printf(\nOutput from head again :\n)。 outlist(head)。 } } 二、程序改错题 include /************found************/ fun (char a) { if ( *a ) { fun(a+1)。 /************found************/ printf(%c *a)。 } } main( ) { char s[10]=abcd。 printf(处理前字符串 =%s\n 处理后字符串 =, s)。 fun(s)。 printf(\n)。 } 三、程序编写题 include char *fun ( char *s, char *t) { } main( ) { char a[20],b[20]。 void NONO ( )。 printf(Input 1th string:)。 gets( a)。 printf(Input 2th string:)。 gets( b)。 printf(%s\n,fun (a, b ))。 NONO ()。 } void NONO ( ) {/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *fp, *wf。 int i。 char a[20], b[20]。 fp = fopen(K:\\k01\\24010001\\,r)。 wf = fopen(K:\\k01\\24010001\\,w)。 for(i = 0。 i 10。 i++) { fscanf(fp, %s %s, a, b)。 fprintf(wf, %s\n, fun(a, b))。 } fclose(fp)。 fclose(wf)。 } 第 7 套题 一、程序填空题 include include define N 8 typedef struct list { int data。 struct list *next。 } SLIST。 void fun( SLIST *h) { SLIST *p, *q。 p=hnext。 if (p!=NULL) { q=pnext。 while(q!=NULL) { if (pdata==qdata) { pnext=qnext。 /**********found**********/ free(___1___)。 /**********found**********/ q=p___2___。 } else { p=q。 /**********found**********/ q=q___3___。 } } } } SLIST *creatlist(int *a) { SLIST *h,*p,*q。 int i。 h=p=(SLIST *)malloc(sizeof(SLIST))。 for(i=0。 iN。 i++) { q=(SLIST *)malloc(sizeof(SLIST))。 qdata=a[i]。 pnext=q。 p=q。 } pnext=0。 return h。 } void outlist(SLIST *h) { SLIST *p。 p=hnext。 if (p==NULL) printf(\nThe list is NULL!\n)。 else { printf(\nHead)。 do { printf(%d,pdata)。 p=pnext。 } while(p!=NULL)。 printf(End\n)。 } } main( ) { SLIST *head。 int a[N]={1,2,2,3,4,4,4,5}。 head=creatlist(a)。 printf(\nThe list before deleting :\n)。 outlist(head)。 fun(head)。 printf(\nThe list after deleting :\n)。 outlist(head)。 } 二、程序改错题 include define N 20 void fun(int a[], int n) { int i, j, t, p。 for (j = 0。 j n1。 j++) { /************found************/ p = j for (i = j+1。 i n。 i++) if(a[i] a[p]) /************found************/ p = j。 t = a[p]。 a[p] = a[j]。 a[j] = t。 } } main() { int a[N]={9,6,8,3,1},i, m = 5。 printf(排序前的数据 :)。 for(i = 0。 i m。 i++) printf(%d ,a[i])。 printf(\n)。 fun(a,m)。 printf(排序后的数据 :)。 for(i = 0。 i m。 i++) printf(%d ,a[i])。 printf(\n)。 } 三、程序编写题 include define M 100 void fun ( int m, int *a , int *n ) { } main( ) { int aa[M], n, k。 void NONO ( )。 fun ( 50, aa, amp。 n )。 for ( k = 0。 k n。 k++ ) if((k+1)%20==0) printf(\n)。 else printf( %4d, aa[k] )。 printf(\n)。 NONO( )。 } void NONO ( ) {/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */ FILE *fp, *wf。 int i, n, j, k, aa[M], sum。 fp = fopen(K:\\k01\\24010001\\,r)。 wf = fopen(K:\\k01\\24010001\\,w)。 for(i = 0。 i 10。 i++) { fscanf(fp, %d, amp。 j)。 fun(j, aa, amp。 n)。 sum = 0。 for(k = 0。 k n。 k++) sum+=aa[k]。 fprintf(wf, %d\n, sum)。 } fclose(fp)。 fclose(wf)。 } 第 8 套题 一、程序填空题 include include define N 8 typedef struct list { int data。 struct list *next。 } SLIST。 SLIST *creatlist(char *)。 void outlist(SLIST *)。 int fun( SLIST *h, char ch) { SLIST *p。 int n=0。 p=hnext。 /**********found**********/ while(p!=__0_1___) { n++。 /**********found**********/ if (pdata==ch) return _n__2___。 else p=pnext。 } return 0。 } main() { SLIST *head。 int k。 char ch。 char a[N]={39。 m39。 ,39。 p39。 ,39。 g39。 ,39。 a39。 ,39。 w39。 ,39。 x39。 ,39。 r39。 ,39。 d39。 }。 head=creatlist(a)。 outlist(head)。 printf(Enter a letter:)。 scanf(%c,amp。 ch)。 /**********found**********/ k=fun(___3___)。 if (k==0) printf(\nNot found!\n)。 else printf(The sequence number is : %d\n,k)。 } SLIST *creatlist(char *a) { SLIST *h,*p,*q。 int i。 h=p=(SLIST *)malloc(sizeof(SLIST))。 for(i=0。 iN。 i++) { q=(SLIST *)malloc(sizeof(SLIST))。 qdata=a[i]。 pnext=q。 p=q。 } pnext=0。 return h。 } void outlist(SLIST *h) { SLIST *p。 p=hnext。 if (p==NULL) printf(\nThe list is NULL!\n)。 else { printf(\nHead)。 do { printf(%c,pdata)。 p=pnext。 } while(p!=NULL)。 printf(End\n)。 } } 二、程序改错题 include include include fun ( char *p) { int i,t。 char c[80]。 /************found************/ For (i = 0,t = 0。 p[i]。 i++) if(!isspace(*(p+i))) c[t++]=p[i]。 /************found************/ c[t]=\0。 strcpy(p,c)。 } main( ) { char c,s[80]。 int i=0。 printf(Input a string:)。 c=getchar()。 while(c!=39。 39。 ) { s[i]=c。 i++。 c=getchar()。 } s[i]=39。 \039。 fun(s)。 puts(s)。 } 三、程序编写题 include include void fun ( char *ss ) { } main( ) { char tt[81]。 void NONO ( )。 printf( \nPlease enter an string within 80 characters:\n )。 gets( tt )。 printf( \n\nAfter changing, the string\n \%s\, tt )。 fun( tt )。 printf( \n。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。