




已阅读5页,还剩29页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
一、阅读程序写出程序运行结果阅读以下程序并写出其运行结果#include #include int fun(char s,int c) char *q=s; for(; *q; q+) if(*q != c) *(s+)=*q; *s=0; main() static char str=turbo c and borland c+; char ch; fun(str,c); printf(str=%sn,str); system(pause);程序的运行结果是str=turbo and Borland +阅读以下程序并写出其运行结果#include #include void fun(int a, int b, long *c) *c=a/10*10+a%10*1000+b/10*100+b%10; main() int a=42,b=25; long c; fun(a, b, &c); printf(The result is: %ldn, c); system(pause);程序的运行结果是 the result is: 2245 请按任意键继续阅读以下程序并写出其运行结果#include void fun(int *s, int nl, int n2) int i, j, t ; i=nl; j=n2; while(ij) t=si; si=sj; sj=t; i+; j-; main() int a10=1,2,3,4,5,6,7,8,9,0,k;fun(a,0,3); fun(a,4,9); fun(a,0,9); for(k=0;k10;k+)printf(“%d”,ak); printf(“n”); 程序运行的结果是 5678901234 Press any key to continue阅读以下程序并写出其运行结果#include main() int i=1; while(!(i%2=1)&(i%3=2)&(i%5=4)&(i%6=5)&(i%7=0) +i; printf(n The ladder has %d stages.n,i); 程序的运行结果是阅读以下程序并写出其运行结果#include #define ROW 3#define COL 4main()int matrixAROWCOL=11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22; int matrixBCOLROW;int i,j;printf(%d*%d:n,ROW,COL);for( i=0; iROW; i+ ) for( j=0; jCOL; j+ )matrixBji = matrixAij;printf(MatrixB,);printf(%d*%d:n,COL,ROW);for( i=0; iCOL; i+ )for( j=0; jROW; j+ )printf(%8d,matrixBij);printf(n);system(pause);程序的运行结果是3*4 Matrix B 4*311 15 1912 16 2013 17 2114 18 22阅读以下程序并写出其运行结果#include #define N 10main()int primesN;int pc,m,k;printf(n The first %d prime numbers are:n,N);primes0=2;pc =1;m =3;while(pcN)k=0;while(primesk*primesk=m)if(m%primesk=0) m+=2; k=1;elsek+;primespc+=m;m+=2;for(k=0;kpc;k+)printf(%4d,primesk);system(pause);程序的运行结果是the fiest 10 prime numbers are2 3 5 7 11 13 17 19 23 29阅读以下程序并写出其运行结果#include #include void fun(char *s ,int n) char *t; int i,j; for(i=0;in-1;i+) for(j=i+1;jstrlen(sj) t=si;si=sj;sj=t;main() char *ss=“bcc”,”bbcc”,”xy”,”aaaacc”,”aabcc” ;fun(ss,5); printf(“%s,%sn”,ss0,ss4);程序的运行结果是阅读以下程序并写出其运行结果#include void fun(char *a, char *b) while(*a=*) a+; while(*b=*a) b+;a+;main() char *s=”*a*b*”,t80;fun(s,t); puts(t); 程序的运行结果是阅读以下程序并写出其运行结果#include main() FILE *fp; int a10=1,2,3,i,n;fp=fopen(“dl.dat”,”w”);for(i=0;i3;i+) fprintf(fp,”%d”,ai);fprintf(fp,”n”);fclose(fp);fp=fopen(“dl.dat”,”r”);fscanf(fp,”%d”,&n);fclose(fp);printf(“%dn”,n);程序的运行结果是阅读以下程序并写出其运行结果#include void swap( int *a, int *b ) int *t ; t=a; a=b; b=t; main() int i=3,j=5,*p=&i,*q=&j; swap(p,q); printf(“%d %dn”,*p,*q); 程序的运行结果是阅读以下程序并写出其运行结果int circle(int n, int d)int s=0,m=n;while(m)s=s*d+m%d;m/=d;return s=n;int num=232,27,851;int scale=2,10,16;main()int i,j;for(i=0;isizeof(num)/sizeof(num0);i+)for(j=0;j (%d) is a Circle Number!n,numi,scalej);elseprintf(%d - (%d) is not a Circle Number!n,numi,scalej);程序的运行结果是 答案太长不想写阅读以下程序并写出其运行结果#include #define NULL 0int *search2(int *pa,int *pb,int an,int bn)int *ca,*cb;ca=pa;cb=pb;while(capa+an&cbpb+bn)if(*ca*cb) cb+;elsereturn ca;/*返回在这两个数表中找到相等元素*/return NULL;main( )int *vp,i;int a =1,3,5,7,9,13,15,27,29,37;int b =2,4,6,8,10,13,14,27,29,37;puts(The elements of array a is:);for(i=0;isizeof(a)/sizeof(a0);i+)printf( %d,ai);puts(nThe elements of array b is:);for(i=0;isizeof(b)/sizeof(b0);i+)printf( %d,bi);vp=search2(a,b,sizeof a/sizeof a0,sizeof b/sizeof b0);if(vp) printf(nThe first same number in both arrays is %dn,*vp);else printf(Not found!n);程序的运行结果是阅读以下程序并写出其运行结果#include main()int i, j;char ch;i=1;while(i=5)j=1;ch=a;while(j=i)printf(%2c, ch);ch=ch+1;j+;printf(n);i+; 程序的运行结果是阅读以下程序并写出其运行结果#include rest(int a, int n)int i,low,high,t;for(i=0,low=0,high=n-1;i0)t=ai;ai=ahigh;ahigh=t;high-;else if(ai=0)i+;elset=ai;ai=alow;alow=t;low+;i+;int s=8,4,0,-1,6,0,-5;main()int i;printf(n The arry before rest is:n);for(i=0;isizeof(s)/sizeof(s0);i+)printf(%4d,si);rest(s,sizeof(s)/sizeof(s0);printf(n The arry after rest is:n);for(i=0;isizeof(s)/sizeof(s0);i+)printf(%4d,si);程序的运行结果是the arry before rest is 8 4 0 -1 6 0 -5 the arry after rest is -5 -1 0 0 6 4 8阅读以下程序并写出其运行结果#include #include typedef struct char name9; char sex; float score2; STU;void f( STU a) STU b=“Zhao” ,m,85.0,90.0 ; int i;strcpy(,);a.sex=b.sex;for(i=0;i2;i+) a.scorei=b.scorei;main() STU c=“Qian”,p,95.0,92.0;f(c); printf(“%s,%c,%2.0f,%2.0fn”,,c.sex,c.score0,c.score1); 程序的运行结果是阅读以下程序并写出其运行结果 #include main() int x,y,z,j=0; printf(n The possible plans to buy 100 fowls with 100 Yuan are:nn); for(x=0;x=20;x+) for(y=0;y=33;y+) z=100-x-y; if(z%3=0&5*x+3*y+z/3=100) printf(%2d: cock=%2d hen=%2d chicken=%2dn,+j,x,y,z); 程序的运行结果是阅读以下程序并写出其运行结果#include void fun(int x) if(x/20) fun(x/2); printf(“%d ”,x); main() fun(3); printf(“n”); 程序的运行结果是阅读以下程序并写出其运行结果#define MAX(a,b) (ab)?a:bmain()int x, y;x=25;y=56;printf(the result is: %dn, MAX(x,y);程序的运行结果是the result is 56阅读以下程序并写出其运行结果 #include #define ROWS 4#define COLS 4int numsROWSCOLS=1000,1000,1000,1000, 900,500,400,100, 90,50,40,10, 9,5,4,1;char *romsROWSCOLS=m,m,m,m, cm,d,cd,c, xc,l,xl,x, ix,v,iv,i;main(int argc,char *argv )int low=1000,high=1012;char roman25;for(;low=high;low+)to_roman(low,roman);printf(%dt%sn,low,roman);system(pause);to_roman(int decimal,char roman )int power,index;roman0=0;for(power=0;powerROWS;power+)for(index=0;index=numspowerindex)strcat(roman,romspowerindex);decimal-=numspowerindex;程序的运行结果是1000 m 1001 mi 1002 mii 1003 miii 1004 miv 1005 mv 1006 mvi 1007 mvii 1008 mviii 1009 mix 1010 mx 1011 mxi 1012 mxii#include int Fun(int x) static int y = 0;y += x;return y; main() int x = 10, y = 0, k;for(k=0; k2; k+) y = Fun(x);printf(y = %dn, y); 运行结果是:#includemain ( )char a = programming , b = language ;char *p1, *p2 ;int i;p1 = a; p2 = b;for (i=0; i7; i+)if (*(p1+i) = *(p2+i) printf(%c ,*(p1+i) ;printf(n);运行结果是: #include main()int a=10; int a=15; printf(“a.1=%d,”,a); printf(“a.2=%dn”,a);运行结果是:#include main()int i=0; while(1) printf(“*”); i+; if(i3) break;printf(“n”);运行结果是:int runc(int a,int b)return(a+b);main()int x=2,y=5,z=8,r;r=runc(runc(x,y),z);printf(“%dn”,r);执行结果是: 15阅读以下程序并写出其运行结果#incude main()int i, n3, n2, n1;i=1;while(i=99)n3=i/100;n2=(i-n3*100)/10;n1=i%10;if(i%3=0)&(n2=5|n1=5)printf(%5d, i);i+;程序的运行结果是 15 45 51 54 57 75阅读以下程序并写出其运行结果 main ( ) int a66,i,j ; for (i=1; i6 ; i+) for (j=1 ; j6 ; j+) aij=(i/j)*(j/i) ; for (i=1;i6 ; i+) for (j=1 ; j6 ; j+) printf(“%2d”,aij) ; printf(“n”); 程序的运行结果是 1000001000001000001000001阅读以下程序并写出其运行结果#include #include struct ks int a; int *b ; s4, *p ;main ( ) int n=1, i ; for (i=0 ; ia,(p+)-a) ;程序的运行结果是阅读以下程序并写出其运行结果#include void fun(int *s, int nl, int n2) int i, j, t ; i=nl; j=n2; while(ij) t=si; si=sj; sj=t; i+; j-; main() int a10=1,2,3,4,5,6,7,8,9,0,k;fun(a,0,3); fun(a,4,9); fun(a,0,9); for(k=0;k10;k+)printf(“%d”,ak); printf(“n”); 程序运行的结果是阅读以下程序并写出其结果func (int a,int b) static int m=0,i=2; i+=m+1; m=i+a+b; return (m);main ( ) int k=4,m=1,p1,p2; p1=func(k,m) ; p2=func(k,m) ; printf(“%d,%dn”,p1,p2) ;程序的运行结果是 8 17阅读以下程序并写出其运行结果struct man char name20 ; int age ; person = “liming”, 18, “wanghua”, 19,”zhangping”,20 ;main ( ) int old = 0 ; struct man *p=person, *q ; for ( ; p=&person2; p+) if (oldage) q=p ; old=p-age ; printf(“$s %dn”,q-name,q-age) ;程序的运行结果是 zhongping 20阅读以下程序并写出其运行结果 #include main() int x,y,z,j=0; printf(n The possible plans to buy 100 fowls with 100 Yuan are:nn); for(x=0;x=20;x+) for(y=0;y=33;y+) z=100-x-y; if(z%3=0&5*x+3*y+z/3=100) printf(%2d: cock=%2d hen=%2d chicken=%2dn,+j,x,y,z); 程序的运行结果是阅读以下程序并写出其运行结果#include void fun(int x) if(x/20) fun(x/2); printf(“%d ”,x); main() fun(3); printf(“n”); 程序的运行结果是阅读以下程序并写出其运行结果#define MAX(a,b) (ab)?a:bmain()int x, y;x=25;y=56;printf(the result is: %dn, MAX(x,y);程序的运行结果是 没找上答案阅读以下程序并写出其运行结果 #include #define ROWS 4#define COLS 4int numsROWSCOLS=1000,1000,1000,1000, 900,500,400,100, 90,50,40,10, 9,5,4,1;char *romsROWSCOLS=m,m,m,m, cm,d,cd,c, xc,l,xl,x, ix,v,iv,i;main(int argc,char *argv )int low=1000,high=1012;char roman25;for(;low=high;low+)to_roman(low,roman);printf(%dt%sn,low,roman);system(pause);to_roman(int decimal,char roman )int power,index;roman0=0;for(power=0;powerROWS;power+)for(index=0;index=numspowerindex)strcat(roman,romspowerindex);decimal-=numspowerindex;程序的运行结果是 没找上答案阅读以下程序并写出其运行结果#incude main()int i, n3, n2, n1;i=1;while(i=99)n3=i/100;n2=(i-n3*100)/10;n1=i%10;if(i%3=0)&(n2=5|n1=5)printf(%5d, i);i+;程序的运行结果是 没找上答案二填空题,在下列代码段中的空白处填入正确的语句 以下程序求3个整数的最小公倍数,请填空#inlcude int fun(int, tint , int );main() int x1, x2, x3, i=1, j, x0; printf(input 3 integers:); scanf(%d%d%d, &x1, &x2, &x3); x0=fun(x1, x2, x3); while(1) j=x0*i; if_j%x1=0&_j%x2=0&j%x3=0 _break; i+; printf(Result is %dn,j);int fun(int x, int y, int z) if(xy & xz) return x; else if_yx &yz_ return y; else return z;以下程序的功能是计算函数,请填空使程序完整。# include ;main ( ) float x,y,z,f ; scanf(“%f,%f,%f”,&x,&y,&z); f = fun ( ); f += fun ( ); printf(“f=%d”,f);float fun(float a,float b) return (a/b) ;下述程序用“碾转相除法”计算两个整数m和n的最大公约数。该方法的基本思想是计算m和n相除的余数,如果余数为0则结束,此时的被除数就是最大公约数。否则,将除数作为新的被除数,余数作为新的除数,继续计算m和n相除的余数,判断是否为0,等等,请填空使程序完整。 main ( ) int m,n,w; scanf(“%d,%d”,&m,&n); while (n) w = m%n ; m = n ; n = m ; printf(“%d”,m);以下函数求s=请填空float fun(int n)int i;double s1=0, s2=_,s3=_, s=0;for(i=1; i=n; i+)s3=s3*i;s1=_;for(i=1; i=n; i+)s2=s2+_;_;return s; 下面以下程序输出a, b, c三个变量中的最小值,请填空。 #include main() int a, b, c, t1, t2; scanf(%d%d%d, &a, &b, &c); t1=ab?_a:b_; t2=ct1?_c:t1_; printf(%dn, t2);已知如下公式: 下面程序的功能使根据上述公式输出满足精度要求的eps的值,请填空使程序完整。main ( ) double s = 0.0, eps, t=1.0; int n ; scanf (“%lf”,&eps); for (n=1 ; ; n+) s+=t ; t= ; ;计算1+1/2+1/4+1/50的值,并显示出来。 main() int i=2; float sum=1.0; while(i= 50 ) sum+=1/ double i ; i+=2; printf(“sum=%fn”,sum); Fibonacci数列中的头两个数是1和1,从第三个数开始,每个数等于前两个数之和。下述程序计算此数列的前20个数,且每行输出5个数,请填空。#include main() int f,f1=1,f2=1; int i; printf(“%6d,%6d”,f1,f2); for (i=3;i=20;i+) f= f1+f2 ; printf(“%6d”,f); if( !ci%5 )printf(“n”); f1=f2; f2=f ; 以下函数用于求出数组grade中n个值的平均数aver,将大于 aver的值置于数组over中,,返回大于平均数的数值的个数。请填空。int fun(int* grade, intn, int* over) int i, j=0; flaot aver, s=0.0; for(i=0; in; i+)s=s+gradei; _; for(i=0; iaver)_=gradei; retrun j; 以下程序从名为 filea.dat 的文本文件中逐个读入字符并显示在屏幕上。请填空:#include main() FILE *fp; char ch ; fp=fopen(“filea.dat”,”r ”) ; ch=fgetc(fp) ; whlie( !feof(fp) ) putchar(ch) ; ch=fgetc(fp);putchar(n); fclose(fp); 下面函数的功能是将一个整数字符串转换为一个整数,例如: 1234 转换为1234,请填空使程序完整。int chnum(char *p) int num=0, k, len, j ; len = strlen(p) ; for ( ; *p!=10 ; p+) k = *p0 ; j=(-len) ; while ( j-!=0 ) k = k*10 ; num = num + k ; return (num);完成以下字符串拷贝函数(将*from串拷贝到*to串):void copy_string(char *from, char *to)for(; *from != 0; _;)_; toi=0; 以下程序从键盘输入10个整数到数组a, 然后依次输出10个数组元素#include void main() int *p,i,a10; p=a; for(i=0;i10;i+) scanf(%d,p+); printf(n);_; for(_) printf(%d ,*p);所谓“水仙花数”是指一个3位数,其各位数字的立方和等于该数本身。例如,153是一个“水仙花数”,因为153135333。完成以下程序使之可打印出1001000内的全部”水仙花数“。main ( ) int i,j,k,n; printf(“水仙花数”是:”); for (n=100; n1000; n+)i= n/100; /*取百位数*/ j=_; /*取十位数*/ k=n%10; /*取个位数*/ if (_) printf(“%4d”,n); printf(“n”);以下程序用来求两整数的绝对值和。请填空。#includevoid main()int x,y; printf(Please input x,y:); scanf(%d%d,&x,&y); if (x0) _ ; if (_) y=-y; printf(n|x|+|y|=%dn,x+y); 以下程序可计算1名学生10门课成绩的平均分,将缺省语句填上。#includefloat average(float array10) int i;float aver,sum=array0;for(i=1;i10;i+) sum += _;aver = sum / 10;return(aver);void main()float score10,aver;int i;printf(n input 10 scores:);for(i=0;i10;i+) scanf(%f,&scorei);aver= _ ;printf(n average score is %5.2fn,aver);以下程序中函数 fun 的功能是:统计 person 所指结构体数组中所有性别(sex)为 M 的记录的个数,存入变量 n 中,并做为函数值返回。请填空:#include#define N 3 typedef struct i
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 二零二五年度货车挂靠经营与培训合同
- 2025版智能电网改造工程担保辅修合同
- 二零二五版教育培训合作协议范本
- 二零二五年度安全生产事故调查处理责任书
- 二零二五年度股权众筹平台股权出让合同标准模板
- 二零二五年房地产贷款风险评估及监控服务协议
- 二零二五年度木材深加工订单生产合同范本
- 二零二五年度房屋抵押贷款与房地产中介服务合同范本
- 二零二五年度合同编号:现代农业项目造价咨询服务合同
- 二零二五年度二手房置换合同范本封面
- 酒体设计师-国家职业标准
- 血友病性关节炎
- DB14∕T 92-2010 M5、M15车用甲醇汽油
- 期中综合测试卷(第一单元至第四单元)(试题)-2024-2025学年人教版五年级数学上册
- 中建三局安装工程“防高坠”安全管理图册
- 劳务派遣外包人力资源采购投标方案(技术方案)
- 《人际沟通与礼仪(第五版)》全套教学课件
- 分布式光伏项目工程竣工验收报告
- 2023年甘肃省职业院校技能大赛土木工程无损检测赛项规程及样题(高职学生组)
- 室内软装设计项目教程-教案 软装资源元素
- 知识题库-人社劳动知识竞赛测试题及答案(十四)
评论
0/150
提交评论