实验程序作业流程设计选择结构程序设计_第1页
实验程序作业流程设计选择结构程序设计_第2页
实验程序作业流程设计选择结构程序设计_第3页
实验程序作业流程设计选择结构程序设计_第4页
实验程序作业流程设计选择结构程序设计_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

渣海工学窿奸等机科学系

试验汇报书

课程名:《c语言程序设计A》

题目:试验2程序步骤设计

——选择结构程序设计

班级:软嵌151

学号:

姓名:

评语:

成绩:指导老师:

批阅时间:年月日

1、试验内容或题目

(1)编写一个程序,输入一个字母,若为大写字母,将其转换为小写字母后输出,

不然原样输出。

(2)编写一个程序判定用户输入字符是数字字符、字母字符还是其它字符。

(3)编写一个程序,输入年号和月份,判定该年是否为闰年,并依据给出月份判定

是什么季节和该月有多少天?闰年条件是年号能被4整除但不能被100整除,或能被400

整除。

(4)编写一个程序,求ax2+bx+c=0方程根。

(5)给出一个百分制成绩,要求输出成绩等级'A','B','C','D,,'E'。

90分以上为'A',80〜89分为'B',70〜79分为'C',60〜69分为'D',60分以

下为'E'。(要求使用switch语句)

2、试验目标和要求

(1)深入熟悉熟悉VC++6编译环境,掌握利用VC编译C程序基础方法;

(2)学会使用C语言常见运算符,和包含这些运算符表示式;

(3)掌握常见步骤控制结构(次序、选择),学会利用这两种控制结构编写C程序。

3、试验步骤和源程序

⑴试验步骤

⑴、

(2)、

(3)、

开始

(4)、

(5)、

⑵源代码

⑴、

#include<stdio.h>

intmain()

(

charch;

scanf("%c",&ch);

if(ch>='A'&&div=Z)

(

ch+=32;

printf("%c\n",ch);

)

else

printf("%c\n",ch);

return0;

⑵、

#include<stdio.h>

intmain()

(

charch;

ch=getchar();

if(ch>='0'&&ch<=9)

printf(“您输入是数字字符\n");

elseif(ch>=宣&&ch<='z'||ch>=A'&&ch<='Z')

printf(“您输入是字母字符\n");

else

printf(“您输入是其它字符\n");

return0;

)

⑶、

#include<stdio.h>

intmain()

intyear,month,daysjeap;

scanf("%d%d",&year,&month);

if(year%4==0&&year%100!=0||year%400==0)

leap=l;

else

leap=0;

if(leap)

printf("%disaleapyear\n",year);

else

printf("%disnotaleapyear\n",year);

if(leap=l)

if(month==2)

printf("themonthhas29days\n");

elseif(month==l||3||5||7||8||10||12)

printf("themonthshas31days\n*');

else

printf("themonthshas30days\n");

if(leap=0)

if(month==2)

printf("themonthhas28days\n");

elseif(month==l||3||5||7||8||10||12)

printf("themonthshas31days\n");

else

printf(Mthemonthshas30days\n");

if(month>=3&&month<=5)

printf("spring\n");

elseif(month>=6&&month<=8)

printf("summer\n");

elseif(month>=9&&month<=ll)

printf("autumn\n");

else

printf("winter\n");

return0;

}

⑷、

#include<stdio.h>

#include<math.h>

voidmain()

doublea,b,c,disc,xl,x2,p,q;//disc是判别式sqrt(b*b-4ac)

printf("请输入[a,b,center]\n");

scanf("%lf%lf%lf",&a,&b,&c);

disc=b*b-4*a*c;

if(0==a)

if(O==b)

if(O==c)

printf(“此方程有任意解.\n");

else〃a=0b=0c!=o

printf("此方程无解.\rT);

}

else〃a=0b=!0

(

xl=-c/b;x2=-c/b;

printf(“此方程解为:xl=x2=%lf\n”,xl,x2);

)

)

if(O!=a)

(

if(disc<0)

printf(“此方程无实数根\n");

else

(

p=-b/(2.0*a);

q=sqrt(disc)/(2.0*a);

xl=p+q;x2=p-q;

printf(“此方程两个实数根为:xl=%7.2f,x2=%7.2f\n”,xLx2);

⑸、

#include<stdio.h>

intmain()

(

intscore;

printf("Youscore:");

scanf("%d",&score);

switch((int)score/10)

(

case10:

case9:

printf("Yougrade:A\n");

break;

case8:

printf("Yougrade:B\n");

break;

case7:

printf("Yougrade:C\n");

break;

case6:

printf("Yougrade:D\n");

break;

case5:

case4:

case3:

case2:

case1:

case0:

printf("Yougrade:E\n");

break;

)

return0;

4、测试数据和试验结果(能够抓图粘贴)

⑴、

--D:\EXAMTEMP\Debug\example349.exe',0I回

(2)

*'D:\EXAMTEMP\Debug\example349.exe-

3输入的是数字字符

IPressanykeytocontinue

*-D:\EXAMTEMP\Debug\example349.exe-

慢输入的是字母字符

Pressanykeytocontinue

(3)、

♦,D:传习\Debug\example349.exe"

20002

2000isaleapyear

themonthhas29days

winter

Pressanykeytocontinue

*,D:修习\Debug\example349.exe-闻

201511

2015isnotaleapyear

themonthshas31days

autumn

Pressanykeytocontinue

⑷、

*'D:\DEBUG\Debug\example349.exe"回

请输入enter]

000

此方程有任意解.

IPressanykeytocontinue

w-D:\DEBUG\Debug\example349.exe''回

请输入[a,b,center]

002

此方程无解.

Pressanykeytocontinue

*'D:\DEBUG\Debug\example349.exe"

请输入【a,b,center]

02-2

此方程的解为:xl=x2=1.000000

IPressanykeytocontinue.

,口回

*"D:\DEBUG\Debug\example349.exe"।

请输入【a,b,center]

L-21

此方程的两个实数根为:xi=l-00,x2=1.00

1Pressanykeytocontinue

⑸、

♦,D:修习\Debug\example349.exe"

Vouscore:100

Vougrade:A

Pressanykeytocontinue

,D:修习\Debug\exampe349.exe"

Vouscore:80

Yougrade

Pressanykeytocontinue

-*D:>^3\Debug\exampe349.exe"

Vouscore:70

Yougrade:C

Pressanykey

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论