ImageVerifierCode 换一换
格式:DOCX , 页数:104 ,大小:1.27MB ,
资源ID:3973893      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/3973893.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(c语言二级填空答案.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

c语言二级填空答案.docx

1、c语言二级填空答案填空题1#include #include #define N 6typedef struct node int data; struct node *next; NODE;void fun(NODE *h) NODE *p, *q; int t;/*found*/ p = _1_ ; h-next /*因为是带有头节点,头节点不存内容所以,不取头节点*/ while (p) /*found*/ q = _2_ ; p-next /*从p指向的下个节点开始比较*/ while (q) /*found*/ if (p-data _3_ q-data) t = p-data; p

2、-data = q-data; q-data = t; q = q-next; p = p-next; NODE *creatlist(int a) NODE *h,*p,*q; int i; h = (NODE *)malloc(sizeof(NODE); h-next = NULL; for(i=0; idata=ai; q-next = NULL; if (h-next = NULL) h-next = p = q; else p-next = q; p = q; return h;void outlist(NODE *h) NODE *p; p = h-next; if (p=NULL

3、) printf(The list is NULL!n); else printf(nHead ); do printf(-%d, p-data); p=p-next; while(p!=NULL); printf(-Endn); main() NODE *head; int aN= 0, 10, 4, 2, 8, 6 ; head=creatlist(a); printf(nThe original list:n); outlist(head); fun(head); printf(nThe list after sorting :n); outlist(head);2#include #d

4、efine M 3#define N 4void fun(int (*a)N) int i=0,j,find=0,rmax,c,k; while( (iM) & (!find) rmax=ai0; c=0; for(j=1; jN; j+) if(rmaxaij) /*found*/ rmax=aij; c= _1_ ; j /*下面看出c作为列号,所以c=j*/ find=1; k=0; while(kM & find) /*found*/ if (k!=i & akc=rmax) find= _2_ ; 0 /* find 作为标志 ,值只能是1 or 0 ,此处之前find =1 ,所以

5、现在改变为0*/ k+; if(find) printf(find: a%d%d=%dn,i,c,aic);/*found*/ _3_ ; i+; /*补充完while 大循环,若无i+,则循环不能结束*/ if(!find) printf(not found!n);main() int xMN,i,j; printf(Enter number for array:n); for(i=0; iM; i+) for(j=0; jN; j+) scanf(%d,&xij); printf(The array:n); for(i=0; iM; i+) for(j=0; jN; j+) printf(

6、%3d,xij); printf(nn); fun(x);3#include #include #define M 5#define N 20int fun(char (*ss)N, int *n) int i, k=0, len= N;/*found*/ for(i=0; i /* *n 来存放大的长度,谁比它大,它就要谁*/ *n=len; k=i; /*found*/ return(_3_); k /* k是最长的字符串的下标*/main() char ssMN=shanghai,guangzhou,beijing,tianjing,chongqing; int n,k,i; print

7、f(nThe original strings are :n); for(i=0;iM;i+)puts(ssi); k=fun(ss,&n); printf(nThe length of shortest string is : %dn,n); printf(nThe shortest string is : %sn,ssk);4#include void fun(char *s, char *p) int i, j, n, x, t; n=0; for(i=0; si!=0; i+) n+; for(i=1; in-2; i=i+2) /*found*/ _1_; t=i /* 设置t为i所

8、在位置 */*found*/ for(j=_2_+2 ; jsj) t=j; if(t!=i) x=si; si=st; st=x; for(i=1,j=0; in; i=i+2, j+) pj=si;/*found*/ pj=_3_; 0 /*字符串最后补0作为结束*/main() char s80=baawrskjghzlicda, p50; printf(nThe original string is : %sn,s); fun(s,p); printf(nThe result is : %sn,p);5#include void fun(char *s, int *t) int i,

9、n; n=0;/*found*/ for(i=0; _1_ !=0; i+) si /*下标指向的内容不是0的话,继续循环*/*found*/ if(si=0&si= _2_ ) n+; 9/*si的范围是0到9*/*found*/ _3_ ; *t=n /*循环结束 *t 取n的值*/main() char s80=abcdef35adgh3kjsdf7; int t; printf(nThe original string is : %sn,s); fun(s,&t); printf(nThe result is : %dn,t);6#include unsigned long fun(u

10、nsigned long n) unsigned long x=0; int t; while(n) t=n%10;/*found*/ if(t%2=_1_) 0 /*t%2=0 说明t是偶数*/*found*/ x=_2_+t; x*10 /*让x 进位到10位 , 让t 为个位数 ,比如3和2 组成一个数 3 *10+2 正好是32 , */*found*/ n=_3_; n/10 /* n/10让n变小一位,通过循环将n所有的数都拿出来*/ return x;main() unsigned long n=-1; while(n99999999|n0) printf(Please inpu

11、t(0n100000000): ); scanf(%ld,&n); printf(nThe result is: %ldn,fun(n);7#include #define N 9int fun(int a, int n) int i,j; j = 0; for (i=0; in; i+)/*found*/ if (ai%2=_1_) 1 /*奇数判断*/ /*found*/ aj = ai; _2_; j+ /* aj赋值后 j+ */ /*found*/ return _3_; j /*j作为下标,可以用来计个数*/main() int bN=9,1,4,2,3,6,5,8,7, i, n

12、; printf(nThe original data :n); for (i=0; iN; i+) printf(%4d , bi); printf(n); n = fun(b, N); printf(nThe number of odd : %d n, n); printf(nThe odd number :n); for (i=0; in; i+) printf(%4d , bi); printf(n);8#include #include #include int fun(char *s) char *lp,*rp;/*found*/ lp= _1_ ; s /.* lp 指向字符串最

13、开头 正好是s所指向的位置*/ rp=s+strlen(s)-1; while(toupper(*lp)=toupper(*rp) & (lprp) ) /*found*/ lp+; rp _2_ ; - /* lp+ rp- lp向后移动 rp 向前移动 */*found*/ if(lprp) _3_ ; return 0 /* 当循环结束,看看那个条件结束的,如果是lprp 则比较到了最后,如果是(toupper(*lp)=toupper(*rp) 结束,则证明有*lp *rp 不相同,此时不是 回文*/ else return 1;main() char s81; printf(Ente

14、r a string: ); scanf(%s,s); if(fun(s) printf(n%s is a Palindrome.nn,s); else printf(n%s isnt a Palindrome.nn,s);9#include #include void fun( int *a, int n ) int i; for(i=0; in; i+) /*found*/ if( _1_=0 ) i%5 /*每行输出几个数,就和几求余*/*found*/ printf(_2_); n /*每五个输出换行*/*found*/ printf(%d ,_3_); ai /*输出数据*/ mai

15、n() int a100=0, i,n; n=22; for(i=0; in;i+) ai=rand()%21; fun( a, n); printf(n);10#include int fun(int x) int n, s1, s2, s3, t; n=0; t=100;/*found*/ while(t=_1_) 999 /*t的范围是0-999 */*found*/ s1=t%10; s2=(_2_)%10; s3=t/100; t/10 /*个位数是 t%10 十位数 是 t/10 %10 百位数 是 t/100 */*found*/ if(s1+s2+s3=_3_) x /*各位数

16、字之和是输入的x的值*/ printf(%d ,t); n+; t+; return n;main() int x=-1; while(x0): ); scanf(%d,&x); printf(nThe result is: %dn,fun(x);11#include double fun(int n) int i, k; double s, t; s=0;/*found*/ k=_1_; 1 /*根据第一项定k的初值为1*/ for(i=1; i=n; i+) /*found*/ t=_2_; 2*i /*t * t 做分子可以得出t=2*i*/ s=s+k*(2*i-1)*(2*i+1)/

17、(t*t);/*found*/ k=k*_3_; (-1) /*k每次乘以 -1每项变正负号*/ return s;main() int n=-1; while(n0): ); scanf(%d,&n); printf(nThe result is: %fn,fun(n);12#include #include #define N 80void fun(char *s, int n, char *t) int len,i,j=0; len=strlen(s);/*found*/ if(n=len) strcpy(_1_); t , s /*将s 复制给t */ else /*found*/ f

18、or(i=len-n; i=len-1; i+) tj+= _2_ ; si /*根据条件将s的内容给t */*found*/ tj= _3_ ; 0 /*字符串最后加0结束*/ main() char sN,tN; int n; printf(Enter a string: );gets(s); printf( Enter n:); scanf(%d,&n); fun(s,n,t); printf(The string t : ); puts(t);13.#include int fun(char *s, char *t) int n=0; while(*s) if(*s 97) /*fou

19、nd*/ *(t+n)= _1_ ; n+; *s /*如果*s小于97 将*s 放入t所指向的数组中*/*found*/ _2_ ; s+ /*s指针后移 配合while 循环*/ *(t+n)=0;/*found*/ return _3_ ; n /*返回t所指向数组中的数据个数*/main() char s81,t81; int n; printf(nEnter a string:n); gets(s); n=fun(s,t); printf(nThere are %d letter which ASCII code is less than 97: %sn,n,t);14#includ

20、e void fun(char *s, int a, double f)/*found*/ _1_ fp; FILE * /*定义文件指针格式,这个必须记住(必须的)*/ char ch; fp = fopen(file1.txt, w); fprintf(fp, %s %d %fn, s, a, f); fclose(fp); fp = fopen(file1.txt, r); printf(nThe result :nn); ch = fgetc(fp);/*found*/ while (!feof(_2_) fp /*feof() 函数是判断文件是否结束,如果结束,返回0 ,函数的参数是

21、判断的文件的文件指针*/*found*/ putchar(_3_); ch = fgetc(fp); ch /* 输出 ch */ putchar(n); fclose(fp);main() char a10=Hello!; int b=12345; double c= 98.76; fun(a,b,c);15#include #define M 3#define N 5void fun(int (*a)N,int k) int i,j,p,temp;/*found*/ for(p=1; p= _1_; p+) k /*这个地方的条件判断必须看下面循环体的作用是什么,通过程序我们可以看出,循环

22、体的作用是将最后一列放到开头,也就是左移一列。那么我们要左移k次,所以条件是p=k (注意,p=1 开始的)*/ for(i=0; iM; i+) temp=ai0;/*found*/ for(j=0; j _2_ ; j+) aij=aij+1; N-1 /* jN-1表示先通过for 循环左移N-1次,然后把temp 放到最后,完成循环体功能。*/*found*/ aiN-1= _3_; temp /*注意 temp 内存放的是第一个内容,在以后完成之后,我们将其放到每行的最后*/ main( ) int xMN= 1,2,3,4,5,1,2,3,4,5,1,2,3,4,5 ,i,j; p

23、rintf(The array before moving:nn); for(i=0; iM; i+) for(j=0; jN; j+) printf(%3d,xij); printf(n); fun(x,2); printf(The array after moving:nn); for(i=0; iM; i+) for(j=0; jN; j+) printf(%3d,xij); printf(n); 16# include #define N 9void fun(int a, int n) int i,j, max, min, px, pn, t; for (i=0; in-1; i+=2) /*found*/ max = min = _1_; ai /*设置循环max min 的值都为ai 以

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1