欢迎来到天天文库
浏览记录
ID:47201777
大小:27.09 KB
页数:20页
时间:2019-08-24
《C语言程序设计慕课下编译答案(完美)》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、.1求最大公约数和最小公倍数(15分)#includeintfun1(intm,intn)//辗转相除法求m/n的公约数{intr;while(n){r=m%n;m=n;n=r;}returnm;}intfun2(intm,intn)//最小公倍数{returnm*n/fun1(m,n);}intmain(){inta,b;scanf("%d,%d",&a,&b);//输入printf("最大公约数:%d最小公倍数:%d",fun1(a,b),fun2(a,b));return0;}2排序并插入(15分)#include2、io.h>voidInsertionSort(int*arr,intn)//插入排序{int*last=0,*next=0,key=0,i=0;for(i=1;i3、=*last;*next=key;}}}voidOutPutArray(constint*arr,intn)//打印一个数组{inti;for(i=0;i4、&key);//输入一个数if(key5、arr+8);InsertNumber(arr,10);//调用函数,将输入的第10个数插进去。OutPutArray(arr,10);//输出return(0);}3.最大公约数#includeintfun1(intm,intn)//辗转相除法求m/n的公约数{intr;while(n){r=m%n;m=n;n=r;}returnm;}intmain(){inta,b;scanf("%d,%d",&a,&b);//输入printf("%d",fun1(a,b));return0;}4.奇数球和..#include6、intmain(){intn;intsum(intn);scanf("%d",&n);printf("%d",sum(n));}intsum(intn){intb;if(n>1)b=sum(n-1)+2*n-1;if(n==1)b=1;returnb;}5.巧算自然数#includeintstep=1;voidfc(intn)//输出n这个数并按角谷猜想对n做处理以便进入下一步。返回值是总步数。{if(n==1){printf("%d",n);return;}elseif(n%2==0){printf("%d,",n);fc(n/27、);step++;}else{printf("%d,",n);fc(n*3+1);step++;}}intmain(intargc,char*argv[]){intn;scanf("%d",&n);..fc(n);printf("step=%d",step);return0;}6.卖鸭子#includeintmain(){staticinti,x[8];x[7]=2;for(i=7;i>=0;i--)x[i-1]=(x[i]+1)*2;printf("sum=%d",x[0]);for(i=0;i<7;i++)printf(8、"sell=%d,",x[i]-x[i+1]);printf("");ret
2、io.h>voidInsertionSort(int*arr,intn)//插入排序{int*last=0,*next=0,key=0,i=0;for(i=1;i3、=*last;*next=key;}}}voidOutPutArray(constint*arr,intn)//打印一个数组{inti;for(i=0;i4、&key);//输入一个数if(key5、arr+8);InsertNumber(arr,10);//调用函数,将输入的第10个数插进去。OutPutArray(arr,10);//输出return(0);}3.最大公约数#includeintfun1(intm,intn)//辗转相除法求m/n的公约数{intr;while(n){r=m%n;m=n;n=r;}returnm;}intmain(){inta,b;scanf("%d,%d",&a,&b);//输入printf("%d",fun1(a,b));return0;}4.奇数球和..#include6、intmain(){intn;intsum(intn);scanf("%d",&n);printf("%d",sum(n));}intsum(intn){intb;if(n>1)b=sum(n-1)+2*n-1;if(n==1)b=1;returnb;}5.巧算自然数#includeintstep=1;voidfc(intn)//输出n这个数并按角谷猜想对n做处理以便进入下一步。返回值是总步数。{if(n==1){printf("%d",n);return;}elseif(n%2==0){printf("%d,",n);fc(n/27、);step++;}else{printf("%d,",n);fc(n*3+1);step++;}}intmain(intargc,char*argv[]){intn;scanf("%d",&n);..fc(n);printf("step=%d",step);return0;}6.卖鸭子#includeintmain(){staticinti,x[8];x[7]=2;for(i=7;i>=0;i--)x[i-1]=(x[i]+1)*2;printf("sum=%d",x[0]);for(i=0;i<7;i++)printf(8、"sell=%d,",x[i]-x[i+1]);printf("");ret
3、=*last;*next=key;}}}voidOutPutArray(constint*arr,intn)//打印一个数组{inti;for(i=0;i4、&key);//输入一个数if(key5、arr+8);InsertNumber(arr,10);//调用函数,将输入的第10个数插进去。OutPutArray(arr,10);//输出return(0);}3.最大公约数#includeintfun1(intm,intn)//辗转相除法求m/n的公约数{intr;while(n){r=m%n;m=n;n=r;}returnm;}intmain(){inta,b;scanf("%d,%d",&a,&b);//输入printf("%d",fun1(a,b));return0;}4.奇数球和..#include6、intmain(){intn;intsum(intn);scanf("%d",&n);printf("%d",sum(n));}intsum(intn){intb;if(n>1)b=sum(n-1)+2*n-1;if(n==1)b=1;returnb;}5.巧算自然数#includeintstep=1;voidfc(intn)//输出n这个数并按角谷猜想对n做处理以便进入下一步。返回值是总步数。{if(n==1){printf("%d",n);return;}elseif(n%2==0){printf("%d,",n);fc(n/27、);step++;}else{printf("%d,",n);fc(n*3+1);step++;}}intmain(intargc,char*argv[]){intn;scanf("%d",&n);..fc(n);printf("step=%d",step);return0;}6.卖鸭子#includeintmain(){staticinti,x[8];x[7]=2;for(i=7;i>=0;i--)x[i-1]=(x[i]+1)*2;printf("sum=%d",x[0]);for(i=0;i<7;i++)printf(8、"sell=%d,",x[i]-x[i+1]);printf("");ret
4、&key);//输入一个数if(key5、arr+8);InsertNumber(arr,10);//调用函数,将输入的第10个数插进去。OutPutArray(arr,10);//输出return(0);}3.最大公约数#includeintfun1(intm,intn)//辗转相除法求m/n的公约数{intr;while(n){r=m%n;m=n;n=r;}returnm;}intmain(){inta,b;scanf("%d,%d",&a,&b);//输入printf("%d",fun1(a,b));return0;}4.奇数球和..#include6、intmain(){intn;intsum(intn);scanf("%d",&n);printf("%d",sum(n));}intsum(intn){intb;if(n>1)b=sum(n-1)+2*n-1;if(n==1)b=1;returnb;}5.巧算自然数#includeintstep=1;voidfc(intn)//输出n这个数并按角谷猜想对n做处理以便进入下一步。返回值是总步数。{if(n==1){printf("%d",n);return;}elseif(n%2==0){printf("%d,",n);fc(n/27、);step++;}else{printf("%d,",n);fc(n*3+1);step++;}}intmain(intargc,char*argv[]){intn;scanf("%d",&n);..fc(n);printf("step=%d",step);return0;}6.卖鸭子#includeintmain(){staticinti,x[8];x[7]=2;for(i=7;i>=0;i--)x[i-1]=(x[i]+1)*2;printf("sum=%d",x[0]);for(i=0;i<7;i++)printf(8、"sell=%d,",x[i]-x[i+1]);printf("");ret
5、arr+8);InsertNumber(arr,10);//调用函数,将输入的第10个数插进去。OutPutArray(arr,10);//输出return(0);}3.最大公约数#includeintfun1(intm,intn)//辗转相除法求m/n的公约数{intr;while(n){r=m%n;m=n;n=r;}returnm;}intmain(){inta,b;scanf("%d,%d",&a,&b);//输入printf("%d",fun1(a,b));return0;}4.奇数球和..#include
6、intmain(){intn;intsum(intn);scanf("%d",&n);printf("%d",sum(n));}intsum(intn){intb;if(n>1)b=sum(n-1)+2*n-1;if(n==1)b=1;returnb;}5.巧算自然数#includeintstep=1;voidfc(intn)//输出n这个数并按角谷猜想对n做处理以便进入下一步。返回值是总步数。{if(n==1){printf("%d",n);return;}elseif(n%2==0){printf("%d,",n);fc(n/2
7、);step++;}else{printf("%d,",n);fc(n*3+1);step++;}}intmain(intargc,char*argv[]){intn;scanf("%d",&n);..fc(n);printf("step=%d",step);return0;}6.卖鸭子#includeintmain(){staticinti,x[8];x[7]=2;for(i=7;i>=0;i--)x[i-1]=(x[i]+1)*2;printf("sum=%d",x[0]);for(i=0;i<7;i++)printf(
8、"sell=%d,",x[i]-x[i+1]);printf("");ret
此文档下载收益归作者所有