第11页共75页 if(s[]<0)s[i>7) printf( "Error: %c not is ocatal digits \nIn"s[D); exit(O); printf(" the ocaral string: ) puts(s) n=fun(s) printf("n%s is convered to integer number: %dinIn,S, n) 12、给定程序中,函数fun的功能是:求出在字符串中最后一次出现的子字符串的地址,通 过函数值返回,在主函数中输出从此地址开始的字符串;若未找到则函数值为NULL。例如 当字符串s中的内容为: abcdabfabcdx,子串t中的内容为:abc时,输出结果应为: abcd。 当子串t中的内容为:abd时,输出未找到信息: Notbe found!。 请改正函数fun中指定部位的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序 include <stdio. h>> /*****水* found**水**冰**/ char fun( char *s, char * t I char *p, * r a=NULL /水**冰水*冰*水* found*率冰****/ while(ar) if(r==p)r++;p++;} if(*r==0)a=s; /*水***水** found**率*/ retrun a maino i char s[50]=abcdabfabcdx", t[50] printf the string s: %s\n\n",s printf Enter substring: ) gets(t) p=fun(s, t) if(p)printf (" \nThe result is: %s\n, p) else printf (" \nNot be found \n") 13、下列程序中,fun函数的功能是:根据形参m,计算如下公式的值 t=1+1/2+1/3+%+…+1/ 例如,若输入5,则应输出2.283333 唯C动力(htp:/www.clearner.net)版权所有
第 11 页 共 75 页 唯 C 动力(http://www.clearner.net)版权所有 if(s[i]<’0’)||s[i]>7) {printf(“Error :%c not is ocatal digits !\n\n”,s[i]);exit(0);} printf(“the ocaral string: ”); puts(s); n=fun(s); printf(“\n%s is convered to integer number : %d\n\n”,s,n); } 12、给定程序中,函数 fun 的功能是:求出在字符串中最后一次出现的子字符串的地址,通 过函数值返回,在主函数中输出从此地址开始的字符串;若未找到则函数值为 NULL。例如, 当字符串 s 中的内容为:abcdabfabcdx,子串 t 中的内容为:abc 时,输出结果应为:abcdx。 当子串 t 中的内容为:abd 时,输出未找到信息:Notbe found!。 请改正函数 fun 中指定部位的错误,使它能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include <stdio.h> /**********found**********/ char fun( char *s, char *t ) { char *p, *r, *a; a=NULL; /**********found**********/ while( s ) { p=s; r=t; while(*r) /**********found**********/ if( r==p ) r++; p++; } else break; if( *r==0 ) a=s; s++; } /**********found**********/ retrun a; } main() { char s[50]= "abcdabfabcdx", t[50], *p; printf("The string s: %s\n\n",s ); printf("Enter substring: "); gets(t); p=fun(s,t); if(p)printf("\nThe result is: %s\n", p ); else printf("\nNot be found !\n"); } 13、下列程序中,fun 函数的功能是:根据形参 m,计算如下公式的值。 t=1+ 1/2 + 1/3 + ¼ + … + 1/m 例如,若输入 5,则应输出 2.283333
第12页共75页 请改正程序中的语法错误,使程序能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构 试题程序 #includeconio. h> #include<stdio. h> double fun (int m double t=l 0 for(i=2: i<=m: i++) /****冰水** found***水*/ t+=1.0/k /******* found*冰*冰冰**/ maino int m clrscro printf(“ nPlease enter 1 integer number:"”); scan printf(“ nThe result is%lfn”,fun(m) 14、下列程序中,fun和funx函数的功能是 用二分法求方程2x×x×x-4x×x+3x-6=0的一个根,并要求绝对误差不超过0.001。例 如,若给m输入-100,给n输入90,则函数求得的一个根为2.000。 请改正程序中的语法错误,使程序能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序 #include<stdio. h #include<math. h double funx(double x) return(2*x*x*x-4=*x*x+3*x-6) double fun(double m, double n /*****水* found******/ int r r=(m+n)/2 /**水***** found水****冰水 唯C动力(htp:/www.clearner.net)版权所有
第 12 页 共 75 页 唯 C 动力(http://www.clearner.net)版权所有 请改正程序中的语法错误,使程序能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include<conio.h> #include<stdio.h> double fun(int m) { double t=1.0; int i; for(i=2;i<=m;i++) /**********found***********/ t+=1.0/k; /**********found***********/ ____________; } main() { int m; clrscr(); printf(“nPlease enter 1 integer number:”); scanf(“%d”,&m); printf(“nThe result is %1fn”,fun(m)); } 14、下列程序中,fun 和 funx 函数的功能是: 用二分法求方程 2x×x×x-4x×x+3x-6=0 的一个根,并要求绝对误差不超过 0.001。例 如,若给 m 输入-100,给 n 输入 90,则函数求得的一个根为 2.000。 请改正程序中的语法错误,使程序能得出正确的结果。 注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include<stdio.h> #include<math.h> double funx(double x) { return(2*x*x*x-4*x*x+3*x-6); } double fun(double m, double n) { /**********found***********/ int r; r=(m+n)/2; /**********found***********/
13页共75页 while(fabs(n-m)<0. 001) lif(fun(x)*funx(n)<0 m= se n-n r=(m+n)/2; return r maln double m.n. root printf (" Enter m n: n): scanf(%1f%lf", &m, &n) root=fun (m, n) printf( root=%6. 3fn", root) 15、下列给定程序中,函数fun的功能是:判断字符ch是否与str所指串中的某个字符相 同;若相同,则什么也不做,若不同,则将器插在串的最后 请改正程序中的错误,使程序能得出正确的结果 注意,不要改多main函数,不得增行或删行,也不得更改程序的结构 试题程序 #include <conio. h> #include <stdio /*****水** found*****/ void fun (char str, char ch) i while (kstr & *str!=ch) str++ /******* found**冰***/ if (*str==ch) str[O]=ch /*******fOnd水***冰水**/ str[1]=0 (char s[81],c printf("nPlease enter a string: n): gets(s) printf("nPlease enter the character to search: ) fun (s, c) printf("nThe result is %sn, s): 唯C动力(htp:/www.clearner.net)版权所有
第 13 页 共 75 页 唯 C 动力(http://www.clearner.net)版权所有 while(fabs(n-m)<0.001) {if(fun(x)*funx(n)<0 m=r; else n=r; r=(m+n)/2; ) return r; ) main() { double m,n,root; printf("Enter m n:n");scanf("%1f%1f",&m,&n); root=fun(m,n); printf("root=%6.3fn",root); } 15、下列给定程序中,函数 fun 的功能是:判断字符 ch 是否与 str 所指串中的某个字符相 同;若相同,则什么也不做,若不同,则将器插在串的最后。 请改正程序中的错误,使程序能得出正确的结果。 注意,不要改多 main 函数,不得增行或删行,也不得更改程序的结构! 试题程序 #include <conio.h> #include <stdio.h> #include <string.h> /**********found***********/ void fun(char str, char ch) { while(*str && *str!=ch) str++; /**********found***********/ if (*str==ch) { str[0]=ch; /**********found***********/ str[1]='0'; } } main() {char s[81],c; clrscr(); printf("nPlease enter a string:n");gets(s) printf("nPlease enter the character to search:"); c=getchar(); fun(s,c); printf("nThe result is %sn",s); }
第14页共75页 16、下列给定程序中,函数 Creatlink的功能是:创建带头结点的单项链表,并为各结点数 据域赋0到m-1的值。 请改正程序中的错误,使程序能得出正确的结果 注意,不要改多main函数,不得增行或删行,也不得更改程序的结构! 试题程序 #include <conio. h> #include <stdio. h> #include <stdlib. h typedef struct aa i int data struct aa next NODE *Creatlink(int n, int m) (NODE *h=Null S=(NODE *)malloc(sizeof (NODE)) /*水水**** found水***冰水*/ h=p p->next=NULL for (i=1: i<=n: 1++) Is=(NODE *)malloc(sizeof (NODE) s->daa=rand0‰ p=p->next /*水***水** found***率水*/ return p outlink (NODE *h) p=h->next printf(" nnTHE LIST: nn HEAD") while(p) printf("->%d", p->data printf("n") 唯C动力(htp:/www.clearner.net)版权所有
第 14 页 共 75 页 唯 C 动力(http://www.clearner.net)版权所有 16、下列给定程序中,函数 Creatlink 的功能是:创建带头结点的单项链表,并为各结点数 据域赋 0 到 m-1 的值。 请改正程序中的错误,使程序能得出正确的结果。 注意,不要改多 main 函数,不得增行或删行,也不得更改程序的结构! 试题程序 #include <conio.h> #include <stdio.h> #include <stdlib.h> typedef struct aa { int data; struct aa *next; }NODE; NODE *Creatlink(int n, int m) {NODE *h=Null, *p,*s; int i; s=(NODE *)malloc(sizeof(NODE)); /**********found***********/ h=p; p->next=NULL; for (i=1;i<=n;i++) {s=(NODE *)malloc(sizeof(NODE)); /**********found***********/ s->data=rand()%m; s->next=p->next; p->next=s; p=p->next; } /**********found***********/ return p; } outlink(NODE *h) {NODE *p; p=h->next; printf("nnTHE LIST:nn HEAD"); while(p) {printf("->%d",p->data); p=p->next; } printf("n"); }
第15页共75页 maino I NODE *head c⊥rscr head=Creatlink(8, 22) outlink(head) 17、下列给定程序中,函数fun的功能是:计算并输出k以内最大的10个能被13或17整 除的自然数之和。k的值由主函数传入,若k的值为500,则函数值为4622 请改正程序中的错误,使程序能得出正确的结果 注意,不要改多main函数,不得增行或删行,也不得更改程序的结构 试题程序 #include <conio. h #include <stdio. h> lint m=0, mc=0, j while((k>=2)&&(mc<10)) /****冰水** found***水*/ if((k%313=0)(k%17=0) {m=m+k;mc++;} return m 水水水水客客水客 found**冰*冰水*冰*/ Iclrscro printf("%dn", fun(500)) 18、下列给定程序中,函数fun的功能是:实现两个整数的交换。例如给a和b分别输入 60和65,输出为:a=65b=60 请改正程序中的错误,使程序能得出正确的结果 注意,不要改多main函数,不得增行或删行,也不得更改程序的结构! 试题程序 #include <conio. h> finc lude <stdio. h> /*****水* found******/ void fun (int a, b) /**水***** found水****冰水 唯C动力(htp:/www.clearner.net)版权所有
第 15 页 共 75 页 唯 C 动力(http://www.clearner.net)版权所有 main() { NODE *head; clrscr(); head=Creatlink(8,22); outlink(head); } 17、下列给定程序中,函数 fun 的功能是:计算并输出 k 以内最大的 10 个能被 13 或 17 整 除的自然数之和。k 的值由主函数传入,若 k 的值为 500,则函数值为 4622。 请改正程序中的错误,使程序能得出正确的结果。 注意,不要改多 main 函数,不得增行或删行,也不得更改程序的结构! 试题程序 #include <conio.h> #include <stdio.h> int fun(int k) {int m=0, mc=0,j; while ((k>=2)&&(mc<10)) /**********found***********/ {if ((k%13=0)||(k%17=0)) {m=m+k;mc++;} k--; } return m; /**********found***********/ _____________ main() {clrscr(); printf("%dn",fun(500)); } 18、下列给定程序中,函数 fun 的功能是:实现两个整数的交换。例如给 a 和 b 分别输入 60 和 65,输出为:a=65 b=60 请改正程序中的错误,使程序能得出正确的结果。 注意,不要改多 main 函数,不得增行或删行,也不得更改程序的结构! 试题程序 #include <conio.h> #include <stdio.h> /**********found***********/ void fun (int a,b) {int t; /**********found***********/