资源描述:
《c语言作业资料》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、选择作业:1、输入两个运算量和一个运算符,完成加、减、乘、除、取余运算,输出运算结果。#include"stdio.h"main(){intx,y,z;charch;printf("Enteranoperator(+,-,*,/,%):");ch=getchar();printf("Entertwonumbers:");scanf("%d%d",&x,&y);switch(ch){case'+':z=x+y;printf("%d+%d=%d",x,y,z);break;case'-':z=x-y;printf("%d-%d=%d
2、",x,y,z);break;case'*':z=x*y;printf("%d*%d=%d",x,y,z);break;case'/':{if(y==0)printf("divisionbyzero");else{z=x/y;printf("%d/%d=%d",x,y,z);}break;}case'%':{if(y==0)printf("divisionbyzero");else{z=x%y;printf("%d%%%d=%d",x,y,z);}break;}default:printf("Theerroroperator
3、");}}2.用公式f=p*w*s*(1-d)计算运输费。要求运费和路程从#includevoidmain(){floatf,p,w,s,d;intc;printf("pleaseinputhowmuchmony/T:");scanf("%f",&p);printf("pleaseinputhowweight:");scanf("%f",&w);printf("pleaseinputhowloog:");scanf("%f",&s);if(s>=3000)c=12;elsec=s/250;switch(c){cas
4、e0:d=0;break;case1:d=0.02;break;case2:case3:d=0.05;break;case4:case5:case6:case7:d=0.08;break;case8:case9:case10:case11:d=0.10;break;case12:d=0.15;break;}f=p*w*s*(1-d);printf("f=%.2f",f);}3.区分键盘上的字母、数字、空格和回车字符。#includevoidmain(){charc;printf("Pleaseinputacha
5、racter:");c=getchar();if(c==''
6、
7、c=='')printf("Thisisablankorenter");elseif(c>='0'&&c<='9')printf("Thisisadigit.");elseif(c>='a'&&c<='z')printf("Thisisa大写letter.");elseif(c>='A'&&c<='Z')printf("Thisisa小写letter.");elseprintf("Thisisanothercharacter.");}实验三一、编
8、程,输入任意三个数n1,n2,n3,求其中最大的一个数。输入输出示例:inputn1,n2,n3:210.58max=10.50源程序:#includevoidmain(){floatn1,n2,n3,max;printf("pleaseinputn1,n2,n3:");scanf("%f%f%f",&n1,&n2,&n3);max=n1;if(max9、:9103themaxis:10.0Pressanykeytocontinue二、编程,输入x,计算并输出下列分段函数f(x)的值(保留2位小数)。xx<1y=2x-11<=x<103x-11x>=10输入输出示例:inputx:-2.5f(-2.500000)=-2.5源程序:#includevoidmain(){floatx,y;printf("pleaseinputx:");scanf("%f",&x);if(x<1)y=x;elseif(x>=1&&x<10)y=2*x-1;elsey=3*x-1;prin
10、tf("f(%.1f)=%.1f",x,y);}运行结果;第一次运行:pleaseinputx:0.5f(0.5)=0.5Pressanykeytocontinue第二次运行;pleaseinputx:8f(8.0)=15.0Pr