资源描述:
《C语言经典例题和问题详解.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、作业一一、求一个任意边长的矩形面积。#includevoidmain(){intw,h,sum;scanf("%d%d",&w,&h);sum=w*h;printf("area=%d",sum);}二、求一个任意半径的圆的面积及周长。#definePI3.14159#includevoidmain(){floatr,area,c;scanf("%f",&r);area=PI*r*r;c=2*PI*r;printf("area=%fcircle=%f",area,c);}三、已知:w=5,y=4,z=2,求表
2、达式:w*y/z的值,并输出。##includevoidmain(){intw,y,z,r;w=5;y=4;z=2;r=w*y/z;printf("%5d",r);}作业二一、从键盘上输入三个数,求出其中的最大值,并输出。#includevoidmain(){inta,b,c,max;scanf("%d%d%d",&a,&b,&c);max=a;if(max3、(注意:30*3.14159/180)#include#definePI3.14159#includevoidmain(){floata,b,sum;a=30*PI/180;b=60*PI/180;sum=sin(a)+sin(b)+cos(a)+cos(60);printf("total=%f",sum);}一、比较两个数的大小。如果x大于y,则输出:x>y,否则输出:xvoidmain(){intx,y;scanf("%d,%d",&x,&y);if(x>y)printf("
4、x>y");elseprintf("xvoidmain(){inta,b,c,t;scanf("%d%d%d",&a,&b,&c);if(a>b){t=b;b=a;a=t;}if(a>c){t=a;a=c;c=t;}if(b>c){t=b;b=c;c=t;}printf("%3d%3d%3d",a,b,c);}.二、求自然数1~10之和。。#includevoidmain(){inti,sum;i=1;sum=0;while(i<
5、=10){sum=sum+i;i++;}printf("sum=%d",sum);}一、输入10个整数,统计出正数之和以及负数之和。(求奇数之和以及偶数之和)#includevoidmain(){intsum1=0,sum2=0,i,x;i=1;while(i<=10){scanf("%d",&x);if(x%2==0)sum1=sum1+x;elsesum2=sum2+x;i++;}printf("sum1=%dsum2=%d",sum1,sum2);}作业四一、输入一个0~6的整数,转换成星期输出。#include6、dio.h>main(){inta;scanf("%d",&a);switch(a){case0:printf("Sunday");break;case1:printf("Monday");break;case2:printf("Tuesday");break;case3:printf("Wednesday");break;case4:printf("Thursday");break;case5:printf("Friday");break;case6:printf("saturday");break;default:printf("Iamsorry.Yo
7、uarewrong.");}}.一、输入一个整数,将各位数字反转后输出。如:输入365,则输出显示为563。#includevoidmain(){intx,r;scanf("%d",&x);printf("converis:");while(x!=0){r=x%10;printf("%d",r);x=x/10;}printf("");}二、输入一个整数,求出它的所有因子。#includevoidmain(){intx,i;scanf("%d",&x);for(i=1;i<=x;i++)if(x%i==0)pri
8、ntf("%3d",i);}作业五一、求100~200之间的素数。