77范文网 - 专业文章范例文档资料分享平台

c语言作业资料

来源:网络收集 时间:2018-12-04 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

选择作业:

1、输入两个运算量和一个运算符,完成加、减、乘、除、取余运算,输出运算结果。 #include\ main( ) {

int x,y,z; char ch;

printf(\ch=getchar();

printf(\scanf(\switch(ch) {

case '+':z=x+y;printf(\ case '-':z=x-y;printf(\,z);break; case '*':z=x*y;printf(\,z);break; case '/': { if (y==0)

printf(\ else {z=x/y; printf(\ case '%': {if (y==0)

printf(\

else {z=x%y; printf(\

default:printf(\ } } 2.

用公式f=p*w*s*(1-d)计算运输费。要求运费和路程从

# include void main( ) {float f,p,w,s,d; int c;

printf(\printf(\printf(\if(s>=3000) c=12; else c=s/250; switch( c){

case 0: d=0;break; case 1: d=0.02;break; case 2:

case 3: d=0.05;break;

case 4: case 5: case 6: case 7: d=0.08;break; case 8: case 9: case 10: case 11: d=0.10;break; case 12: d=0.15; break; } f=p*w*s*(1-d); printf(\}

3.区分键盘上的字母、数字、空格和回车字符。 # include void main( )

{ char c; printf(\ c = getchar(); if(c==' ' || c=='\\n')

printf(\ else if(c>='0' && c <= '9')

printf(\

else if(c>='a' && c <= 'z' ) printf(\大写 letter.\\n\ else if(c>='A' && c <= 'Z')

printf(\小写 letter.\\n\ else

printf(\}

实验三

一、编程,输入任意三个数n1,n2,n3,求其中最大的一个数。 输入输出示例: input n1,n2,n3: 2 10.5 max=10.50 源程序: #include void main( )

{float n1,n2,n3,max;

printf(\scanf(\max=n1;

if(max

printf(\}

运行结果:

please input n1,n2,n3:9 10 3

8

the max is:10.0

Press any key to continue

二、编程,输入x,计算并输出下列分段函数f(x)的值(保留2位小数)。 x x<1 y= 2x-1 1<=x<10 3x-1 1 x>=10

输入输出示例: input x: -2.5 f(-2.500000)=-2.5 源程序: #include void main()

{float x,y;

printf(\scanf(\if(x<1) y=x;

else if(x>=1&&x<10) y=2*x-1; else y=3*x-1;

printf(\}

运行结果; 第一次运行: please input x:0.5 f(0.5)=0.5

Press any key to continue 第二次运行; please input x:8

f(8.0)=15.0

Press any key to continue 第三次运行: please input x:10 f(10.0)=29.0

Press any key to continue

三、编程,把百分制成绩转换成5级记分制,要求用switch语句。 90分以上(包括90): A 80至90分(包括80):B 70至80分(包括70):C 60至70分(包括60):D 60分以下:E 输入输出示例: input Score: 86 86的等级为B 源程序: #include void main() {float score; int y;

printf(\scanf(\y=(int)(score/10); switch(y) {case 0: case 1: case 2: case 3: case 4: case 5:

printf(\的等级为E\\n\,score); break; case 6:

printf(\的等级为D\\n\,score); break; case 7:

printf(\的等级为C\\n\,score); break; case 8:

printf(\的等级为B\\n\,score); break; case 9: case 10:

printf(\的等级为A\\n\,score); break;} }

第一次运行结果: please input score:100 A

Press any key to continue 第二次运行结果: please input score:86 86.0的等级为B Press any key to continue 第三次运行结果: please input score:50 50的等级为E

Press any key to continue

四、编程,输入2005年的任一个月,输出这个月的天数,要求使用switch语句。 输入输出示例: Input month of 2005: 10 2005年10月有31天 源程序:

#include

void main( ) {int month;

printf(\scanf(\switch(month)

{case 1:case 3:case 5:case 7:

case 8:case 10:case 12: printf(\年%d月有31天\\n\case 2:

printf(\年%d月有28天\\n\case 4:case 6:case 9:case 11:

printf(\年%d月有30天\\n\default: }

printf(\

}

运行结果:

please input a month;1 2005年1月有31天 Press any key to continue

五、改错,对2个整数进行乘、除和求余运算。 源程序(有错误的程序) #include void main() { char sign; int x,y;

prnitf(“输入x 运算符 y:”);

scanf(“%d%c%d”,&x,&sign,&y); if(sign==’*’)

printf(“%d * %d = %d\\n”,x,y,x*y); else if(sign==’/’)

printf(“%d / %d = %d\\n”,x,y,x/y); else if(sign==’%’)

printf(“%d %% %d = %d\\n”,x,y,x%y); else

printf(“运算符输入错误”); }

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库c语言作业资料在线全文阅读。

c语言作业资料.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/339294.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: