1、2.1(1)#include#includemain()int a=2,b=3,m;m=a;a=b;b=m;printf(“a=%d,b=%d“,a,b);getch();(2)#include#include#includemain()float a,b,c,s,v;scanf(“%f,%f,%f“,s=0.5*(a+b+c); /将原来的“1/2”改为“0.5”v=sqrt(s*(s-a)*(s-b)*(s-c);printf(“v=%fn“,v);printf(“a=%f,b=%f,c=%f,s=%fn“,a,b,c,s);getch();(3)#include#includemain(
2、)int i,j,m,n;i=8;j=10;m=+i;n=j+;printf(“%d,%d,%d,%d“,i,j,m,n);getch();书上在此题后有 四次改动“ + ”的位置,不再赘述,其结果依次为:9,11,8,11;8,10;9,11;8,11,9,11;(4)#include#includemain()int i,j,m=0,n=0;i=8;j=10;m+=i+;n-=-j;printf(“i=%d,j=%d,m=%d,n=%d“,i,j,m,n);getch();(5)#include#includemain()int a,b;unsigned c,d;long e,f;a=10
3、0;b=-100;e=50000;f=32767;c=a;d=b;printf(“%d,%dn“,a,b); printf(“%u,%un“,a,b); printf(“%u,%un“,c,b); c=a=e;d=b=f;printf(“%d,%dn“,a,b); printf(“%u,%un“,c,d);getch();上机作业(6)#include#includemain()float a,b,c,S;printf(“*“);printf(“n 请输入长方体相关参数:“);printf(“n 长“);scanf(“%f“,printf(“宽“);scanf(“%f“,printf(“高“)
4、;scanf(“%f“,S=a*b*c;printf(“n 该长方体体积为:%f“,S);printf(“n*“);getch();(7)#include#includemain()int a=3,b=4,c=5,x,y,z;x=c,b,a;y=!a+b#includemain()int a,b,c;printf(“请输入三个整数“);scanf(“%d,%d,%d“,if(a#includemain()int a,b,c,max;scanf(“%d,%d,%d“,max=a;if(bmax)max=b;if(cmax)max=c;printf(“max=%dn“,max);getch();(
5、3)#include#include#includevoid main()float x,y1,y2;printf(“n x=?“);scanf(“%f“,if(x!=0)if(x#include#includevoid main()int score;printf(“n score=?“);scanf(“%d“,switch(score/10)case(10):case (9):printf(“n A“);break;case (8):printf(“n B“);break;case (7):printf(“n C“);break;case (6):printf(“n D“);break;default:printf(“n E“);getch();