您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 大一期末考试c语言操作题答案
ball.c#includestdio.h#definePI3.1415926intmain(){doubler,volume,surface;scanf(%lf,&r);volume=4*PI*r*r*r/3;surface=4*PI*r*r;printf(体积=%10.2f\n,volume);printf(表面积=%10.2f\n,surface);}root.c#includestdio.h#includemath.hintmain(){floata,b,c,x1,x2,delta;scanf(%f%f%f,&a,&b,&c);delta=b*b-4*a*c;x1=(-b+sqrt(delta))/(2.0*a);x2=(-b-sqrt(delta))/(2.0*a);printf(x1=%f,x2=%f\n,x1,x2);}exp04.c#includestdio.hintmain(){intn,x,y,z,sum,product;scanf(%D,&n);x=n/100;y=(n-x*100)/10;z=n%10;sum=x+y+z;product=x*y*z;printf(sum=%d,product=%d\n,sum,product);return0;}year.c#includestdio.hintmain(){intyear;scanf(%d,&year);if((year1)||(year3000)){printf(ERROR!);return0;}if(year%400==0||(year%4==0&&year%100!=0))printf(%d是闰年,year);elseprintf(%d是平年,year);return0;}triangle.c#includestdio.h#includemath.hintmain(){inta,b,c;doubles,p;scanf(%d%d%d,&a,&b,&c);if((a1)||(b1)||(c1)){printf(ERROR);return0;}if((a+bc)&&(a+cb)&&(b+ca)){p=(a+b+c)/2;s=sqrt(p*(p-a)*(p-b)*(p-c));printf(此三角形的面积为%8.2f,s);return0;}elseprintf(不能组成三角形);}add.c#includestdio.h#includemath.hintmain(){inta,b,c;doubles,p;scanf(%d%d%d,&a,&b,&c);if((a1)||(b1)||(c1)){printf(ERROR);return0;}if((a+bc)&&(a+cb)&&(b+ca)){p=(a+b+c)/2;s=sqrt(p*(p-a)*(p-b)*(p-c));printf(此三角形的面积为%8.2f,s);return0;}elseprintf(不能组成三角形);}#includestdio.hintmain(void){intn,sum,i=1;printf(pleaseinputanumber:);scanf(%d,&n);if(n0){printf(ERROR!);}for(i=1;i=n;i++){sum+=i;}return0;}product.c#includestdio.hintmain(void){inti;intn;intp=1;scanf(%d,&n);if(n=0){printf(ERROR);}else{for(i=1;i=n;++i)p*=i;printf(%d,p);}return0;}Sushu.c#includestdio.hintmain(void){inti;intn;intsum=0;scanf(%d,&n);if(n=2){printf(ERROR);}else{for(i=2;in;++i){if(0==n%i)break;}if(i==n)printf(%d是素数\n,n);elseprintf(%d不是素数\n,n);}return0;}Gcd.c#includestdio.hintmain(void){intm,n,p,gcd,lcm;scanf(%d%d,&m,&n);if(m=0||n=0)printf(ERROR);else{p=m*n;while(n!=0){gcd=m%n;m=n;n=gcd;}gcd=m;lcm=p/m;printf(gcd=%d,lcm=%d\n,gcd,lcm);}return0;}Abcd.c#includestdio.hvoidmain(void){inta,b,c,d,e,num;for(num=999;num99;num--){a=num/100;b=num/10%10;c=num%10;for(e=2;e10;e++)for(d=0;d10;d++)if(num*e==d*1000+c*100+b*10+a){printf(abcd=%d,num*10+d);return;}}}Sumsushu.c#includestdio.hintf(intn){inti;intsum=0;if(n!=2){for(i=2;in;i++){if(n%i==0){sum=0;break;}if(n%i!=0)sum=1;}}if(n==2)sum=1;returnsum;}intmain(){intn,a=0,i;scanf(%d,&n);if(n=1)printf(ERROR);else{for(i=2;i=n;i++){if(f(i)==1)a+=i;}printf(素数和=%d,a);}return0;}Fact.c#includestdio.hintzuheshu(intn){inti=1;inttemp1=1,temp2=1;for(i=1;i=2;i++){temp1*=n-i+1;temp2*=i;}temp1/=temp2;returntemp1;}intmain(){intn;scanf(%d,&n);if(n=1)printf(ERROR);else{intsum;sum=zuheshu(n);printf(angles=%d,sum);}}Hanoi.c#includestdio.hintsum=0;voidhanoi(chara,charb,charc,intn){if(n==1){sum++;}else{hanoi(a,c,b,n-1);sum++;hanoi(c,b,a,n-1);}}intmain(){inti,n;scanf(%d,&n);if(n=0)printf(ERROR);else{hanoi('A','C','B',n);printf(移动次数为%d\n,sum);}return0;}Fibonaci.c#includestdio.hintFib(intn){if(n==1||n==2)return1;returnFib(n-1)+Fib(n-2);}intmain(){intm,k;scanf(%d%d,&m,&k);if(m0&&m=k&&k50){inti;longintsum=0;for(i=m;i=k;i++)sum+=Fib(i);printf(sum=%ld\n,sum);}elseprintf(ERROR);return0;}Bubble.c#includestdio.hintmain(void){intn;scanf(%d,&n);if(n0&&n10){inti,j,k,m[n];for(i=0;in;i++)scanf(%d,&m[i]);for(i=0;in-1;i++)for(j=0;jn-i-1;j++)if(m[j]m[j+1]){k=m[j];m[j]=m[j+1];m[j+1]=k;}for(i=0;in;i++)printf(%d\t,m[i]);}elseprintf(ERROR);}Count.c#includestdio.h#includestring.h#defineN100intmain(){intn,m;scanf(%d%d,&n,&m);if(n0&&n20&&m0&&m20){inta[N]={0};inti;intj;for(i=0;in;i++){a[i]=i+1;}while(n1){i=(i+m-1)%n;printf(%d\t,a[i]);for(j=i+1;jn;j++){a[j-1]=a[j];}n--;if(i==n){i=0;}}printf(%d\t,a[i]);}elseprintf(ERROR);return0;}List-find.c#includestdio.h#defineNUM30voidmybubble(int*pArr,intnum){//使用冒泡排序法对数组pArr进行从小到大排序,num为数组元素的个数inti,j,t;for(i=0;inum-1;i++){for(j=0;jnum-i-1;j++){if(pArr[j]pArr[j+1]){t=pArr[j+1];pArr[j+1]=pArr[j];pArr[j]=t;}}}}intmyfind(int*pArr,intkey,intnum){intlow=0,high=num-1,mid;//二分法查找while(low=high){mid=(low+high)/2;//数组pArr已按从小到大排好序,key为要查找的关键字值,num为数组元素的个数if(keypArr[mid]){low=mid+1;}//查找成功,返回该关键字值所在位置的下标,若查找失败则返回-1elseif(keypArr[mid]){high=mid-1;}else{returnmid;}}return-1;}intmain(){intMA[NUM]={34,76,23,67,345,234,21,78,172,90};intnums=10;//数组元素个数intmkey;intk;mybubble(MA,nums);scanf(%d,&mkey);//输入一个整数k=myfind(MA,mkey,nums);if(k0)printf(ERROR\n);elseprintf(SUCCESS\t%d\n,k);return0;}Dispose.c#includestdio.hvoidmain(){intn,i,j=0;scanf(%d,&n);if(n=1||n2000)printf(ERROR);else{for(i=2;i=n;i++){while(n%i==0){j++;if(j==1)printf(%d=%d,n,i);elseprintf(*%d,i);n=n/i;}}}}
本文标题:大一期末考试c语言操作题答案
链接地址:https://www.777doc.com/doc-5715480 .html