资源描述:
《C语言程序代码.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、1、输出一句话‘欢迎进入C语言世界’#includevoidmain(){printf("欢迎进入C语言世界.");getchar();}2、两个数的交换(1)#includevoidmain(){intx,y;x=18;y=19;printf("x=%d,y=%d",x,y);x=x+y;y=x-y;x=x-y;printf("x=%d,y=%d",x,y);}(2)#includevoidmain(){intx,y,z;x=18;y=19;z=x;x=y;y=z;printf("%d,%d"
2、,x,y);}3、屏幕输入两个数相除输出商#includevoidmain(){intx,y;scanf("%d%d",&x,&y);printf("%lf",(double)x/y);}4、固定两个数的交换值#includevoidmain(){intx,y;x=18;y=19;printf("x=%d,y=%d",x,y);x=x+y;y=x-y;x=x-y;printf("x=%d,y=%d",x,y);}5、屏幕输入一组数倒叙输出结果#includevoidmain(){intn,a,b
3、,c;scanf("%d",&n);a=n/100;b=(n/10)%10;c=n%10;printf("倒序输出结果:%d%d%d",c,b,a);}6、屏幕输入一个数,输出结果自动加1#includevoidmain(){inti,j;scanf("%d",&i);j=i++;printf("%dt%d",i,j);}7、指定数比较大小#includevoidmain(){inti,j;i=2;j=3;printf("%d",ij);printf("%d",i<=j)
4、;printf("%d",i>=j);printf("%d",i!=j);printf("%d",i==j);}8、屏幕输入两个数求和除以2#includevoidmain(){inta,b;doublex;scanf("%d%d",&a,&b);x=(a+b)/2.0;printf("%lf",x);}9、屏幕输入成绩判断成绩的等级(1)#includevoidmain(){intx;scanf("%d",&x);switch((int)x/10){case10:case9:printf("优秀");b
5、reak;case8:printf("良好");break;case7:printf("中等");break;case6:printf("及格");break;default:printf("不及格");(2)#includevoidmain(){intx;scanf("%d",&x);switch((int)x/10){case9:printf("A");break;case8:printf("B");break;case7:printf("C");break;case6:printf("D");break;default:
6、printf("E");}}10、屏幕输入成绩对成绩进行判断,通过还是补考#includevoidmain(){doublex;scanf("%lf",&x);if(x>=60){printf("通过");}else{printf("补考");}}11、屏幕输入题级结果,判断对错#includevoidmain(){intx,y,r,z;charc;scanf("%d%c%d=",&x,&c,&y);scanf("%d",&r);switch(c){case'+':z=x+y;break;case'-':z=x-y;brea
7、k;case'':z=xy;break;case'/':z=x/y;break;}if(r==z){printf("对");}else{printf("错");}}(2计算器)#includevoidmain(){intx,y,r,z;charc;scanf("%d%c%d=",&x,&c,&y);scanf("%d",&r);switch(c){case'+':z=x+y;break;case'-':z=x-y;break;case'':z=xy;break;case'/':z=x/y;break;}Printf(“%d”,z)
8、;}(3)循环(双、多分支)计算器#i