资源描述:
《C语言作业总结(简单入门)_免费下载》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、一元二次方程求解#include#includevoidmain(){inta,b,c;doublex1,x2;scanf("%d,%d,%d",&a,&b,&c);if(b*b-4*a*c>0){x1=(-b-sqrt(b*b-4*a*c))/2/a;x2=(-b+sqrt(b*b-4*a*c))/2/a;printf("%lf,%lf",x1,x2);}elseif(b*b-4*a*c==0){x1=x2=(-b-sqrt(b*b-4*a*c))/2/a;printf("%lf,%lf",x1,x2);
2、}elseprintf("无解");}分段函数#includevoidmain(){intx,y;printf("请输入一个数:");scanf("%d",&x);if(x<1)y=x;else{if(x<10)y=2*x-1;elsey=3*x-1;}printf("x=%d,y=%d",x,y);}某月多少天(switch)#includevoidmain(){intyear,month;printf("请输入年份:");scanf("%d",&year);printf("请输入月份:");s
3、canf("%d",&month);switch(month){case1:case3:case5:case7:case8:case10:case12:printf("31天");break;case4:case6:case9:case11:printf("30天");break;case2:if(year%4==0&&year%100!=0
4、
5、year%400==0)printf("29天");elseprintf("28天");break;}}最少运费应用题(switch)#includevoidmai
6、n(){intk,s;floatp,w,d,f;printf("请输入距离(km):");scanf("%d",&s);printf("请输入单价($):");scanf("%f",&p);printf("请输入货物重量(kg):");scanf("%f",&w);if(s>3000)k=12;elsek=s/250;switch(k){case0:d=0;break;case1:d=2;break;case2:case3:d=5;break;case4:case5:case6:case7:d=8;break;case8:case9:cas
7、e10:case11:d=10;break;case12:d=15;break;}f=p*w*s*(1-d/100);printf("%f",f);}水仙花数163页#includevoidmain(){intm,i,j,k;m=100;while(m<=999){i=m/100;j=(m-100*i)/10;k=m-100*i-10*j;if(m==i*i*i+j*j*j+k*k*k)printf("%d",m);m++;}}及格的成绩输出例一15页#includevoidmain(){intn;f
8、loatscore;n=1;printf("请输入10个学生的成绩:");while(n<=10){scanf("%f",&score);if(score>=60)printf("%.1f",score);n++;}}输出8个数中最大数例三16页#includevoidmain(){intx,max,i;i=1;printf("请输入8个整数:");scanf("%d",&x);max=x;while(i<=8){scanf("%d",&x);if(x>=max)max=x;i++;}printf("最大数是:
9、%d",max);}统计字符串中的各元素个数83页第十题#includevoidmain(){charc;intletters=0,space=0,digit=0,other=0;printf("请输入字符串:");while((c=getchar())!='');{if(c>='a'&&c<='z'
10、
11、c>='A'&&c<='Z')letters++;elseif(c=='')space++;elseif(c>='0'&&c<='9')digit++;elseother++;}printf("字母:%d,空格:%
12、d,数字:%d,其他字符:%d",letters,space,digit,other);}4/3,7/4,11/7,18/11……前18项求和#includev