资源描述:
《c语言程序设计实验指导(颜晖_主编)部分参考程序》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C语言程序设计部分实验参考答案实验2#includeintmain(){//2-1-2intc,f=150;c=f*5/9-32*5/9;printf("fahr=%d,celsius=%d",f,c);return0;}#includeintmain(){//2-1-3intc=26,f;f=c*9/5+32;printf("celsius=%d,fahr=%d",c,f);return0;}#includeintmain(){//2-1-4
2、intmath=87,eng=72,comp=93;printf("math=%d,eng=%d,comp=%d,average=%d",math,eng,comp,(math+eng+comp)/3);return0;}#includeintmain(){//2-1/5intn=152,a,b,c;c=n%10;b=(n/10)%10;a=n/100;printf("整数%d的个位数字是%d,十位数字是%d,百位数字是%d",n,c,b,a);return0;}#include
3、intmain(){//2-1-6intx=3,y;y=x*x;printf("%d=%d*%d",y,x,x);printf("%d*%d=%d",x,x,y);return0;}#includeintmain(){//2-2-1doublex,y;printf("Enterx:");scanf_s("%lf",&x);if(x!=0){y=1/x;}else{y=0;}printf("f(%.2f)=%.1f",x,y);return0;}#includ
4、eintmain(){//2-2-2intcelsius,fahr;fahr=100;celsius=5*(fahr-32)/9;printf("fahr=%d,celsius=%d",fahr,celsius);return0;}#includeintmain(){//2-2-3doublemoney,rate,x=1.0;inti,year;printf("Entermoney,yearandrate:");scanf("%lf%d%lf",&money,&ye
5、ar,&rate);for(i=1;i<=year;i++)x=x*(1+rate);printf("intrest=%.2f",money*x-money);return0;}#include#includeintmain(){//2-2-4doublex,y;printf("Enterx");scanf_s("%lf",&x);if(x<0.0)y=pow(x+1,2)+2*x+1/x;elsey=sqrt(x);printf("f(%.2f)=%.2f",x
6、,y);return0;}#include#includeintmain(){//2-2-5doublex,y;printf("Enterx:");scanf_s("%lf",&x);if(x==10)y=1/x;elsey=x;printf("f(%.2f)=%.1f",x,y);return0;}#includeintmain(){//2-2-6intx,y;printf("Enternum1:");scanf_s("%d",&x);printf
7、("Enternum2:");scanf_s("%d",&y);printf("%d+%d=%d",x,y,x+y);printf("%d-%d=%d",x,y,x-y);printf("%d*%d=%d",x,y,x*y);printf("%d/%d=%d",x,y,x/y);printf("%d%%d=%d",x,y,x%y);return0;}#includeintmain(){//2-3-1inti,sum=0;for(i=1;i<=100;i++){sum=
8、sum+i;}printf("sum=%d",sum);return0;}#includeintmain(){//2-3-2inti,m,s=0;printf("Enterm:");scanf("%d",&m);for(i=m;i<=100;i++)s=s+i;printf("sum=%d",s);return0;}#includeintmain(){//2-3-3inti,m,n;