您好,欢迎访问三七文档
1./*文件名:求三个整数之和.c*/#includestdio.hvoidmain(){inta=0,b=0,c=0;intsum;printf(123\n);scanf(%d%d%d,&a,&b,&c);sum=a+b+c;printf(%d+%d+%d=%d\n,a,b,c,sum);}2./*文件名:求一个整数和一个绝对值之和。*/#includestdio.hvoidmain(){inta,b;intsum;printf(1-4\n);scanf(%d%d,&a,&b);sum=a+abs(b);printf(%d+%d=%d\n,a,b,sum);}3./*4-1.cASCII熟悉*/#includestdio.hvoidmain(){unsigneda,b,c;a=65;b=66;c=67;printf(%c%c%c,a,b,c);}4./*求一个数和一个数的绝对值之和*/#includestdio.h#includemath.hvoidmain(){inta,b,sum;a=1,b=-2;printf(input=\n);scanf(%d%d,a,b);sum=a+abs(b);printf(%d+|%d|=%d\n,a,b,sum);}5./*求圆的周长和面积*/#includestdio.hvoidmain()#definePI3.1415926{doubler,s,l;printf(请输入圆的半径:\n);scanf(%lf,&r);s=PI*r*r;l=2*PI*r;printf(s=%.2lfl=%.2lf\n,s,l);}6./*运算符的使用*/#includestdio.hvoidmain(){printf(%d\n,5/4);printf(%f\n,5.0/4);}7./*字符的大小写转换*/#includestdio.hvoidmain(){chara;printf(请输入一个字符,回车结束\n);scanf(%c,&a);if((a='a')&&(a='z')){printf(%c\n,a-32);}elseif((a='A')&&(a='Z')){printf(%c\n,a+32);}else{printf(输的不是字母);}}8./*顺与结构和分支结构编程练习.c*/#includestdio.hvoidmain(){doublev1=15,t1=10*60,s1=0;doublev2=20,t2=0,s2=0;s1=v1*(t2+t1);t2=v1*t1/(v2-v1);s2=v2*t2;printf(t2=%lf\n,t2);printf(s2=%lf公里\n,s2/1000);printf(s1=%lf公里\n,s1/1000);getchar();}9./*大小写字符的转换.c*/#includestdio.hvoidmain(){chara;printf(请输入一个字符,回车结束);scanf(%c,&a);if((a='a')&&(a='z')){printf(%c\n,a-32);}elseif((a='A')&&(a='Z')){printf(%c\n,a+32);}else{printf(您输入的不是字母\n);}getchar();}10.#includestdio.hvoidmain(){inta;printf(65\n);scanf(%d,&a);if(a=65)printf(%c,a);elseif(a=67)printf(%c,a);elseprintf(END!\n);}11./*编写一个程序实现用户输入一个整数,当该整数为65时显示A,为66时显示B,为67时显示C,其它值时显示END结束*/#includestdio.hvoidmain(){inta;printf(请输入一个整数,按空格键结束\n);scanf(%d,&a);if(a==65){printf(%c,a);}if(a==66){printf(%c,a);}elseif(a==67){printf(%c,a);}else{printf(END!\n);}}12./*编写一个程序实现用户输入一个整数,判断它能否被3,5,7整除,如果x能被y整除满足:x%y==0,同时满足&&*/#includestdio.hvoidmain(){inta;printf(请输入一个整数,按回车键结束\n);scanf(%d,&a);if((a%3==0)&&(a%5==0)&&(a%7==0)){printf(%d能够被3,5,7同时整除,a);}else{printf(%d不能同时被3,5,7整除,a);}}13./*编写输入一个整数,将其数值以小于0,10-99,100-999,1000以上分类显示*/#includestdio.hintmain(){inta;printf(请输入一个整数,回车键结束\n);scanf(%d,&a);if(a=0){printf(%d属于小于0\n,a);}if((a=10)&&(a=99)){printf(%d属于10-99\n,a);}if((a=100)&&(a=999)){printf(%d属于100-999\n,a);}elseif(a=1000){printf(%d属于大于1000\n,a);}else{printf(%d不属于任何一类\n,a);}return0;}/*输入今天的年月日,输出明天的年月日.c*/#includestdio.hintmain(){inty,m,d;printf(请输入今天的日期,输入格式为2012327\n);scanf(%d%d%d,&y,&m,&d);if(m==12&&d==31){y=y+1;m=m-11;d=d-30;printf(明天的日期为%d年%d月%d日,y,m,d);}elseif(d==31&&m%2==1||m==10){y=y;m=m+1;d=d-30;printf(明天的日期为%d年%d月%d日,y,m,d);}elseif(d==30&&m%2==0){y=y;m=m+1;d=d-29;printf(明天的日期为%d年%d月%d日,y,m,d);}else{y=y;m=m;d=d+1;printf(明天的日期为%d年%d月%d日,y,m,d);}return0;}/*公交线路的查询.c*/#includestdio.hintmain(){intgjxl;{printf(请输入您要查询的公交线路\n);scanf(%d,&gjxl);}switch(gjxl){case170:printf(呈贡校区\n);break;case47:printf(火车南站\n);break;case69:printf(世博园\n);break;case182:printf(北部客运站\n);break;case70:printf(莲华校区\n);break;default:printf(对不起您输入的线路不在该系统中\n);break;}}
本文标题:C语言编程实例
链接地址:https://www.777doc.com/doc-1570501 .html