您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > C语言程序设计实验指导(颜晖 主编)高等教育出版社
C语言程序设计部分实验参考答案实验2#includestdio.hintmain(){//2-1-2intc,f=150;c=f*5/9-32*5/9;printf(fahr=%d,celsius=%d\n,f,c);return0;}#includestdio.hintmain(){//2-1-3intc=26,f;f=c*9/5+32;printf(celsius=%d,fahr=%d\n,c,f);return0;}#includestdio.hintmain(){//2-1-4intmath=87,eng=72,comp=93;printf(math=%d,eng=%d,comp=%d,average=%d\n,math,eng,comp,(math+eng+comp)/3);return0;}#includestdio.hintmain(){//2-1/5intn=152,a,b,c;c=n%10;b=(n/10)%10;a=n/100;printf(整数%d的个位数字是%d,十位数字是%d,百位数字是%d\n,n,c,b,a);return0;}#includestdio.hintmain(){//2-1-6intx=3,y;y=x*x;printf(%d=%d*%d\n,y,x,x);printf(%d*%d=%d\n,x,x,y);return0;}#includestdio.hintmain(){//2-2-1doublex,y;printf(Enterx:);scanf_s(%lf,&x);if(x!=0){y=1/x;}else{y=0;}printf(f(%.2f)=%.1f\n,x,y);return0;}#includestdio.hintmain(){//2-2-2intcelsius,fahr;fahr=100;celsius=5*(fahr-32)/9;printf(fahr=%d,celsius=%d\n,fahr,celsius);return0;}#includestdio.hintmain(){//2-2-3doublemoney,rate,x=1.0;inti,year;printf(Entermoney,yearandrate:);scanf(%lf%d%lf,&money,&year,&rate);for(i=1;i=year;i++)x=x*(1+rate);printf(intrest=%.2f\n,money*x-money);return0;}#includestdio.h#includemath.hintmain(){//2-2-4doublex,y;printf(Enterx);scanf_s(%lf,&x);if(x0.0)y=pow(x+1,2)+2*x+1/x;elsey=sqrt(x);printf(f(%.2f)=%.2f\n,x,y);return0;}#includestdio.h#includemath.hintmain(){//2-2-5doublex,y;printf(Enterx:);scanf_s(%lf,&x);if(x==10)y=1/x;elsey=x;printf(f(%.2f)=%.1f\n,x,y);return0;}#includestdio.hintmain(){//2-2-6intx,y;printf(Enternum1:);scanf_s(%d,&x);printf(Enternum2:);scanf_s(%d,&y);printf(%d+%d=%d\n,x,y,x+y);printf(%d-%d=%d\n,x,y,x-y);printf(%d*%d=%d\n,x,y,x*y);printf(%d/%d=%d\n,x,y,x/y);printf(%d%%d=%d\n,x,y,x%y);return0;}#includestdio.hintmain(){//2-3-1inti,sum=0;for(i=1;i=100;i++){sum=sum+i;}printf(sum=%d\n,sum);return0;}#includestdio.hintmain(){//2-3-2inti,m,s=0;printf(Enterm:);scanf(%d,&m);for(i=m;i=100;i++)s=s+i;printf(sum=%d\n,s);return0;}#includestdio.hintmain(){//2-3-3inti,m,n;doubles=0.0;printf(Enterm:);scanf(%d,&m);printf(Entern:);scanf(%d,&n);for(i=m;i=n;i++)s=s+1.0/i;printf(sum=%f\n,s);return0;}#includestdio.hintmain(){//2-3-4inti,n;doubles=0.0;printf(Entern:);scanf(%d,&n);for(i=1;i=n;i++)s=s+1.0/(2*i-1);printf(sum=%f\n,s);return0;}#includestdio.hintmain(){//2-3-5inti,n;doubles=1.0,t=1.0,sign=1.0;printf(Entern:);scanf(%d,&n);for(i=1;in;i++){sign=-sign;t=(t+3);s=s+1/t*sign;}printf(sum=%.3f\n,s);return0;}#includestdio.hintmain(){//2-3-6intlow,uper;doublefahr,celsius;printf(Enterlow:);scanf_s(%d,&low);printf(Enteruper:);scanf_s(%d,&uper);printf(fahrcelsius\n);for(fahr=low;fahr=uper;fahr+=2){celsius=5.0/9.0*(fahr-32.0);printf(%3.0f%6.1f\n,fahr,celsius);}return0;}#includestdio.hintmain(){//2-3-7intm,n,i;doublep,sum=0.0;printf(Enterm:);scanf(%d,&m);printf(Entern:);scanf(%d,&n);p=1.0;for(i=1;i=m;i++)p=p*i;sum=sum+p;p=1.0;for(i=1;i=n;i++)p=p*i;sum=sum+p;printf(sum=%.0f\n,sum);return0;}#includestdio.hintmain(){//2-3-8intx,n,i;doublep=1.0;printf(Enterx:);scanf(%d,&x);printf(Entern:);scanf(%d,&n);for(i=1;i=n;i++)p=p*x;printf(%d的%d次方是%.0f\n,x,n,p);return0;}#includestdio.h#includemath.hintmain(){//2-4-1intn,i;printf(Entern:);scanf(%d,&n);for(i=0;i=n;i++)printf(pow(3,%d)=%.0f\n,i,pow(3.0,i));return0;}#includestdio.h#includemath.hintmain(){//2-4-4doublesum=0.0,i;for(i=100;i=1000;i++){sum+=sqrt(i);}printf(sum=%.2f\n,sum);return0;}//return0;}#includestdio.h#includemath.hintmain(){//2-2-5doublex,y;printf(Enterx:);scanf_s(%lf,&x);if(x==10)y=1/x;elsey=x;printf(f(%.2f)=%.1f\n,x,y);return0;}#includestdio.hintmain(){//2-2-6intx,y;printf(Enternum1:);scanf_s(%d,&x);printf(Enternum2:);scanf_s(%d,&y);printf(%d+%d=%d\n,x,y,x+y);printf(%d-%d=%d\n,x,y,x-y);printf(%d*%d=%d\n,x,y,x*y);printf(%d/%d=%d\n,x,y,x/y);printf(%d%%d=%d\n,x,y,x%y);return0;}#includestdio.hintmain(){//2-3-1inti,sum=0;for(i=1;i=100;i++){sum=sum+i;}printf(sum=%d\n,sum);return0;}#includestdio.hintmain(){//2-3-2inti,m,s=0;printf(Enterm:);scanf(%d,&m);for(i=m;i=100;i++)s=s+i;printf(sum=%d\n,s);return0;}#includestdio.hintmain(){//2-3-3inti,m,n;doubles=0.0;printf(Enterm:);scanf(%d,&m);printf(Entern:);scanf(%d,&n);for(i=m;i=n;i++)s=s+1.0/i;printf(sum=%f\n,s);return0;}#includestdio.hintmain(){//2-3-4inti,n;doubles=0.0;printf(Entern:);scanf(%d,&n);for(i=1;i=n;i++)s=s+1.0/(2*i-1);printf(sum=%f\n,s);return0;}#includestdio.hintmain(){//2-3-5inti,n;doubles=1.0,t=1.0,sign=1.0;printf(Entern:);scanf(%d,&n);for(i=1;in;i++){sign=-sign;t=(t+3);s=s+1/t*sign;}printf(sum=%.3f\n,s);return0;}#includestdio.hintmain(){//2-3-6intlow,uper;doublefahr,celsius;printf(Enterlow:);scanf_s(%d,&low);printf(Enteruper:);scanf_s(%d,&uper);printf(fahrcelsius\n);for(fahr=low;fahr=uper;fahr+=2){celsius=5.0/9.0*(fahr-32.0);printf(%3.0f%6.1f\n,fahr,celsius);}return0;}#includestdio.hintmain(){//2-3-7intm,n,i;doublep,sum=0.0;printf(Enterm:);scanf(%d,&m);printf(Entern:);scanf(%d,&n);p=1.0;for(i=1;i=m;i++)p=p*i;sum=sum+p;p=1.0;for(i=1;i=n;i++)p=p*i;sum=sum+p;printf(sum=%.0f\n,sum);return0;}#includestdio.hintmain(){//2-3-8intx,n,i
本文标题:C语言程序设计实验指导(颜晖 主编)高等教育出版社
链接地址:https://www.777doc.com/doc-3262431 .html