顺序、选择结构实验报告

上传人:pu****.1 文档编号:548768366 上传时间:2023-12-04 格式:DOCX 页数:9 大小:98.56KB
返回 下载 相关 举报
顺序、选择结构实验报告_第1页
第1页 / 共9页
顺序、选择结构实验报告_第2页
第2页 / 共9页
顺序、选择结构实验报告_第3页
第3页 / 共9页
顺序、选择结构实验报告_第4页
第4页 / 共9页
顺序、选择结构实验报告_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《顺序、选择结构实验报告》由会员分享,可在线阅读,更多相关《顺序、选择结构实验报告(9页珍藏版)》请在金锄头文库上搜索。

1、实验报告课程名称 程序设计语言C/C+实验项目顺序结构,选择结构编程与调试一、实验目的1掌握C语言中使用最多的一种语句一一赋值语句的使用方法。2. 掌握各种数据类型的输入输出的方法,能正确使用各种格式转换符。3. 掌握选择结构程序设计的方法和用用关系表达式、逻辑表达式表示选择结构的条件。二、实验内容1调试关于各种格式转换符的正确使用方法的程序并验证结果的正确性。2. 编写并调试简单的关于数据类型输入输出的程序。3. 编写并调试运行关于if语句和switch语句使用的程序。三、实验步骤及结果分析1. 从键盘输入两个整数,求两数之和并输出。 #include stdio.hint main ()i

2、nt a,b,c;printf(请输入两个整数:n); scanf(%d,%d, &a, &b);c=a+b;printf(两数之和为:%dn,c);return 0;请输入两个整数:& 24 两数之和为:32Press any key to continue2. 从键盘输入园的半径r,求园的周长C、面积S并输出。#include stdio.h int main() float pai=3.14159;floa t r,C,S;printf(Please enter the radius of the circle:); scanf(%f ,&r);C=2*pai*r;S=pai*r*r;p

3、rintf (The circumference of the circle C is %.2fn,C);printf (The area of the circle is %.2fn,S);return 0;Please enter the radius of the circle:8.8 Th circumferenc of th circle C is 55.29 Th area of th circle is 243. 28Press any key to continue3. 从键盘输入一个小写字母,要求输出其对应的大写字母。 #include stdio.hint main ()c

4、har c1,c2;c1=ge tchar();c2=c1-32;putchar(c2);printf (n);return 0;kKPress any key to continue4输入圆锥的底面圆的半径和高,求圆锥的表面积和体积。s 二兀 r 2 + 兀 rl l 二幸 r 2 + h 2求平方根函数sqrt()r 2可用函数pow(r,2)表示,也可用r*r表示#include stdio.h #includema th.h int main() float pai=3.14159;floa t r,h,l,v,s;printf (Please enter the radiusofth

5、e circle on the base of the cone:);scanf(%f ,&r);printf(Please enter the heightofthe cone:);scanf(%f ,& h);l=sq rt( pow(r,2)+pow(h,2);s=pai*pow(r,2)+pai*r*l;v=pai*pow(r,2)*h/3;cone is %.2fn,s);printf(The surface area of the printf (The volume of the cone is %.2fn,v);return 0;Please enter the radius

6、of rhe circle on the base of the cone:8Fl ease enter the height of the cone:24The surface ares of the cone is 836. 87The volume of the cone is 1608. 49Press any key to continue5.求一个三位正整数各位数上的数字之和。#include stdio.hint main ()int m,n,a,b,c;printf (Please enter a three-digit number:);scanf(%d,&n);a=n/10

7、0;b=n/10-a*10;c=n-a*100-b*10;m二a+b+c;printf(The sum of the digits of this three-digit number is %dn,m);return 0;6.求一元二次方程ax2 + bx + c = 0的根。#include stdio.h#include =0)p二-b/(2.00*a);q=sqr t(disc)/(2.00*a);x1=p+q;x2=p-q;pri ntf (The real roots of t his equa tion are:xl=%.2f;x2=%.2fn,xl,x2); elseprint

8、f (This equation hasn t real roots.n);return 0;Please input the correlation coefficient of this equation: 2, &4The real roots of this equation are: 2l=-0. 59 ; x2=3. 41 Press any key to contitiue7.从键盘输入3个整数,求最大的数。#include stdio.hint main ()int a,b,c,max;printf (Please input three numbers: n); scanf(

9、%d,%d,%d, &a, &b, &c);max二a;if (maxb)max二b;if (maxc)max二c;printf (The largest number is %dn,max);return 0;Please input three numbers:& 24, 11The largest number is 24 Press any key to continuex(x 1)8.有一函数 y = 2x -1(1 x 10)编写程序:输入x,输出y值。#include stdio.h:nt main()int x,y;printf (Please input a number:)

10、;scanf(%d,& x);if(xl)y=x;elseif(x=l&x10)y=2*x_1;elsey=3*x_;prin tf( y=%dn,y); return 0;else if (a=70)&(a80)printf(Your grade is: Cn);else if (a=60)&(a4500)& (a=9000)p=a*0.20-555;else if (a9000)& (a=35000)p=a*0.25T005;else if (a35000)&(a=55000)p=a*0.30-2755;else if (a55000)& (a=80000)p=a*0.35-5505;else p=a*0.45T3505;printf(Your personal income tax amount is :%lfn,p); return 0;Please input your monthly income :2000 Your personal income ta% amount is 0.Press any key to continuePlease input your monthly income :8888Your personal income tax amount is :522. 600000 Press any key to continue

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 学术论文 > 其它学术论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号