200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 计算机二级c 上机答案 计算机二级c语言上机题库及答案(填空类)

计算机二级c 上机答案 计算机二级c语言上机题库及答案(填空类)

时间:2022-03-04 15:35:43

相关推荐

计算机二级c 上机答案 计算机二级c语言上机题库及答案(填空类)

《计算机二级c语言上机题库及答案(填空类)》由会员分享,可在线阅读,更多相关《计算机二级c语言上机题库及答案(填空类)(91页珍藏版)》请在人人文库网上搜索。

1、1.下列给定程序中,函数fun的功能是计算如下公式直到 ,并且把计算结果作为函数值返回。例如,若形参e的值为1e3,则函数返回值为0.551690。请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。注意:部分源程序在文件BLANK1.C中。不得增行或删行,也不得更改程序的结构!#include double fun(double e) int i, k; double s, t, x;s=0; k=1; i=2;/*found*/x=__1__/4;/*found*/while(x __2__ e) s=s+k*x;k=k* (-1);t=2*i;/*found*/x=__3__。

2、/(t*t);i+;return s;main() double e=1e-3;printf(nThe result is: %fn,fun(e);【参考答案】(1)3.0或(double)3(2)(3) (t+1)2. 下列给定程序中,函数fun的功能是:计算如下公式前n项的和并作为函数值返回。例如,当形参n的值为10时,函数返回值为9.612558。请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。注意:部分源程序在文件BLANK1.C中。不得增行或删行,也不得更改程序的结构!#include double fun(int n) int i; double s, t;/*fo。

3、und*/s=__1__;/*found*/for(i=1; i0): ); scanf(%d,&n); printf(nThe result is: %fn,fun(n);【参考答案】(1) 0(2) n(3) (t*t)3.给定程序中,函数fun的功能是:统计形参s所指的字符串中数字字符出现的次数,并存放在形参t所指的变量中,最后在主函数中输出。例如,若形参s所指的字符串为abcdef35adgh3kjsdf7,则输出结果为4。请在下划线处填入正确内容并将下划线删除,使程序得出正确的结果。注意:部分源程序在文件BLANK1.C中。不得增行或删行,也不得更改程序的结构!#include vo。

4、id fun(char *s, int *t) int i, n;n=0;/*found*/for(i=0; ___1___ !=0; i+)/*found*/if(si=0&si#define N 9int fun(int a, int n) int i,j;j = 0;for (i=0; iunsigned long fun(unsigned long n) unsigned long x=0; int t;while(n) t=n%10;/*found*/if(t%2=____1____)/*found*/x=____2____+t;/*found*/n=____3____;return。

5、 x;main() unsigned long n=-1;while(n99999999|n#define N 9void fun(int a, int n) int i,j, max, min, px, pn, t;for (i=0; i___3___) min = aj; pn = j; if (pn != i) t = ai; ai = min; apn = t;if (px = i) px =pn;if (px != i+1) t = ai+1; ai+1 = max; apx = t; main() int bN=9,1,4,2,3,6,5,8,7, i;printf(nThe or。

6、iginal data :n);for (i=0; i/*found*/char fun(char ch)/*found*/if (ch=0 & __9___)/*found*/return 9- (ch-__0_3___);return ch ;main() char c1, c2;printf(nThe result :n);c1=2; c2 = fun(c1);printf(c1=%c c2=%cn, c1, c2);c1=8; c2 = fun(c1);printf(c1=%c c2=%cn, c1, c2);c1=a; c2 = fun(c1);printf(c1=%c c2=%cn。

7、, c1, c2);【参考答案】(1)char(2) ch#include #define M 5#define N 20int fun(char (*ss)N, int *n) int i, k=0, len= N;/*found*/for(i=0; ivoid fun(char *s) int i, j=0, k=0; char t180, t280;for(i=0; si!=0; i+)if(si=0 & si#include #define N 8typedef struct list int data;struct list *next; SLIST;void fun( SLIST 。

8、*h, int x) SLIST *p, *q, *s;s=(SLIST *)malloc(sizeof(SLIST);/*found*/s-data=___1___;q=h;p=h-next;while(p!=NULL & xp-data) /*found*/q=___2___;p=p-next;s-next=p;/*found*/q-next=___3___;SLIST *creatlist(int *a) SLIST *h,*p,*q; int i;h=p=(SLIST *)malloc(sizeof(SLIST);for(i=0; idata=ai; p-next=q; p=q;p-n。

9、ext=0;return h;void outlist(SLIST *h) SLIST *p;p=h-next;if (p=NULL) printf(nThe list is NULL!n);else printf(nHead);do printf(-%d,p-data); p=p-next; while(p!=NULL);printf(-Endn);main() SLIST *head; int x;int aN=11,12,15,18,19,22,25,29;head=creatlist(a);printf(nThe list before inserting:n); outlist(he。

10、ad);printf(nEnter a number : ); scanf(%d,&x);fun(head,x);printf(nThe list after inserting:n); outlist(head);【参考答案】(1)x(2)p(3)s11.下列给定程序中,函数fun的功能是:将形参a所指数组中的前半部分元素中的值与后半部分元素中的值对换。形参n中存放数组中数据的个数,若n为奇数,则中间的元素不动。例如:若a所指数组中的数据为:1、2、3、4、5、6、7、8、9,则调换后为:6、7、8、9、5、1、2、3、4。请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。注意。

11、:部分源程序在文件BLANK1.C中。不得增行或删行,也不得更改程序的结构!#include #define N 9void fun(int a, int n) int i, t, p;/*found*/p = (n%2=0)?n/2:n/2+___1___;for (i=0; i#include #define N 5#define M 10int fun(char (*ss)M, int k) int i,j=0,len;/*found*/for(i=0; ivoid fun(char *s) int i, n, k; char c;n=0;for(i=0; si!=0; i+) n+;/。

12、*found*/if(n%2=0) k=n-___1___ ;else k=n-2;/*found*/c=___2___ ;for(i=k-2; i=1; i=i-2) si+2=si;/*found*/s1=___3___ ;main() char s80=abcdefgh;printf(nThe original string is : %sn,s);fun(s);printf(nThe result is : %sn,s);【参考答案】(1) 1(2) sk或*(s+k)(3) c14.下列给定程序中,函数fun的功能是:在形参ss所指字符串数组中查找与形参t所指字符串相同的串,找到后返。

13、回该串在字符串数组中的位置(即下标值),若未找到则返回1。ss所指字符串数组中共有N个内容不同的字符串,且串长小于M。请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。注意:部分源程序在文件BLANK1.C中。不得增行或删行,也不得更改程序的结构!#include #include #define N 5#define M 8int fun(char (*ss)M,char *t) int i;/*found*/for(i=0; i#include #define N 8typedef struct list int data;struct list *next; SLIST;v。

14、oid fun( SLIST *p) SLIST *t, *s;t=p-next; s=p;while(t-next != NULL) s=t;/*found*/t=t-___1___;/*found*/printf( %d ,___2___);s-next=NULL;/*found*/free(___3___);SLIST *creatlist(int *a) SLIST *h,*p,*q; int i;h=p=(SLIST *)malloc(sizeof(SLIST);for(i=0; idata=ai; p-next=q; p=q;p-next=0;return h;void outli。

15、st(SLIST *h) SLIST *p;p=h-next;if (p=NULL) printf(nThe list is NULL!n);else printf(nHead);do printf(-%d,p-data); p=p-next; while(p!=NULL);printf(-Endn);main() SLIST *head;int aN=11,12,15,18,19,22,25,29;head=creatlist(a);printf(nOutput from head:n); outlist(head);printf(nOutput from tail: n);while (h。

16、ead-next != NULL)fun(head);printf(nn);printf(nOutput from head again :n); outlist(head);【参考答案】(1)next(2) t-data(3) t16.下列给定程序中,函数fun的功能是:逆置数组元素中的值。例如:若a所指数组中的数据为:1、2、3、4、5、6、7、8、9,则逆置后依次为:9、8、7、6、5、4、3、2、1。形参n给出数组中数据的个数。请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。注意:部分源程序在文件BLANK1.C中。不得增行或删行,也不得更改程序的结构!#include。

17、 void fun(int a, int n) int i,t;/*found*/for (i=0; i#include int fun(char *source, char *target) FILE *fs,*ft; char ch;/*found*/if(fs=fopen(source, ___1___)=NULL)return 0;if(ft=fopen(target, w)=NULL)return 0;printf(nThe data in file :n);ch=fgetc(fs);/*found*/while(!feof(___2___) putchar( ch );/*foun。

18、d*/fputc(ch,___3___);ch=fgetc(fs);fclose(fs); fclose(ft);printf(nn);return 1;main() char sfname20 =myfile1,tfname20=myfile2;FILE *myf; int i; char c;myf=fopen(sfname,w);printf(nThe original data :n);for(i=1; i#define N 4void fun(int (*t)N, int m) int i, j;/*found*/for(i=0; i=0; j-)/*found*/tij+___2_。

19、__ =tij;/*found*/for(j=0; j#include struct student long sno;char name10;float score3;void fun(struct student a) struct student b; int i;/*found*/b = __1__;b.sno = 10002;/*found*/strcpy(__2__, LiSi);printf(nThe data after modified :n);printf(nNo: %ld Name: %snScores: ,b.sno, b.name);/*found*/for (i=0。

20、; i#include #include void WriteText(FILE *);void ReadText(FILE *);main() FILE *fp;if(fp=fopen(myfile4.txt,w)=NULL) printf( open fail!n); exit(0);WriteText(fp);fclose(fp);if(fp=fopen(myfile4.txt,r)=NULL) printf( open fail!n); exit(0);ReadText(fp);fclose(fp);/*found*/void WriteText(FILE ___1___) char 。

21、str81;printf(nEnter string with -1 to end :n);gets(str);while(strcmp(str,-1)!=0) /*found*/fputs(___2___,fw); fputs(n,fw);gets(str);void ReadText(FILE *fr) char str81;printf(nRead file and output to screen :n);fgets(str,81,fr);while( !feof(fr) ) /*found*/printf(%s,___3___);fgets(str,81,fr);【参考答案】(1) *fw(2) str(3) str21.下列给定程序中,函数fun的功能是:有NN矩阵,将矩阵的外围元素做顺时针旋转。操作顺序是:首先将第一行元素的值存入临时数组r,然后使第一列成为第一行,最后一行成为第一列,最后一列成为最后一行,再使临时数组中的元素成为最后一列。例如,若N3,有下列矩阵:123456789操作后应为:741852963请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。