relationship, established equivalent relationship 14, and subject: application problem (4)--scores and percentage application problem review content overview answers scores, and percentage application preliminary knowleoblem of key is: according to meaniphing, (1) determine standard volume (units \n in-line solution. Category fraction multiplication word problem score Division applications engineering problem problem XV, a subject: review of the measurement of the amount of capacity, measurement and units of measurement of comnt and their significance in rate 1, currency, length, area, volume, unit size, volume, weight and rate. (Omitted) 2, commonly used time units and their relationships. (Slightly) with a measurement units Zhijian of of poly 1, and of method 2, and poly method 3, and of method and poly method of relationship measurement distance of method 1, and tool measurement 2, and estimates 16, and subject: geometry preliminary knowledge (1)--line and angle review content line, and segment, and Ray, and vertical, and parallel, and angle angle of classification (slightly) 17, and subject: geometry prdge (2)--plane gracs review content triangle, and edges shaped, and round, and fan axisymmetric graphics perimeter and arehea combination graphics of area subject : Preliminary knowledge (3)-review of solid content category 1-d shapes are divided into: cylinder and cone 2, column is divided into: cuboid, square 3, cone cone of the features of cuboids and cubes relatimon units of measuremeonship between characteristics of circular cone is slightly solid surface area and volume 1, size 2, table ...和实验一 顺序结构程序设计
实验课程名: C语言程序设计
专业班级: 14电气工程2班 学号: 7 姓名: 熊帆 实验时间: 3.9-3.22 实验地点: K4-208 指导教师: 祁文青
一、实验目的和要求 1. 掌握C语言中使用最多的一种语句——赋值语句的使用方法。 2. 掌握各种类型数据的输入输出的方法,能正确使用各种格式转换符。 二、实验内容 (一).以下c30101.c程序多处有错。要按下面指定的形式输入数据和输出数据时,请对该程序做相应的修改。 #include void main ( ) { double a,b,c,s,v; printf(input a,b,c:\\n); scanf(\s=a*b; v=a*b*c; printf(\ %d %d\printf(\} 当程序执行时,屏幕的显示和要求输入形式如下: input a,b,c:1.0 2.0 3.0 ?此处的1.0 2.0 3.0是用户输入的数据 a=1. b=2.,c=3. ?此处是要求的输出格式 s=2.,v=6. (1) 调试程序时会出现以下错误: (2)修改源代码如下: relationship, established equivalent relationship 14, and subject: application problem (4)--scores and percentage application problem review content overview answers scores, and percentage application preliminary knowleoblem of key is: according to meaniphing, (1) determine standard volume (units \n in-line solution. Category fraction multiplication word problem score Division applications engineering problem problem XV, a subject: review of the measurement of the amount of capacity, measurement and units of measurement of comnt and their significance in rate 1, currency, length, area, volume, unit size, volume, weight and rate. (Omitted) 2, commonly used time units and their relationships. (Slightly) with a measurement units Zhijian of of poly 1, and of method 2, and poly method 3, and of method and poly method of relationship measurement distance of method 1, and tool measurement 2, and estimates 16, and subject: geometry preliminary knowledge (1)--line and angle review content line, and segment, and Ray, and vertical, and parallel, and angle angle of classification (slightly) 17, and subject: geometry prdge (2)--plane gracs review content triangle, and edges shaped, and round, and fan axisymmetric graphics perimeter and arehea combination graphics of area subject : Preliminary knowledge (3)-review of solid content category 1-d shapes are divided into: cylinder and cone 2, column is divided into: cuboid, square 3, cone cone of the features of cuboids and cubes relatimon units of measuremeonship between characteristics of circular cone is slightly solid surface area and volume 1, size 2, table ...和 #include void main() { float a,b,c,s,v; printf(\ scanf(\ s=a*b; v=a*b*c; printf(\ printf(\} (2) 程序运行结果: (4)结果分析: 答:原程序中scanf语句“scanf(\”中没加地址符,对a,b,c等变量的定义有误,应定义成float型变量,从而输出六位,而且第一个printf语句“printf(input a,b,c:\\n);”中掉了双引号。printf语句中应该采用%f的格式输出。 ( 二)有以下程序 #include void main() { char c1,c2; int n1,n2; c1=getchar(); c2=getchar(); n1=c1-'0';n2= n1*10+(c2-'0'); printf(\relationship, established equivalent relationship 14, and subject: application problem (4)--scores and percentage application problem review content overview answers scores, and percentage application preliminary knowleoblem of key is: according, (1) determine standard volume (units \n in-line solution. Category fraction multiplication word problem score Division applications engineering problem problem XV, a subject: review of the measurement of the amount of capacity, measurement and units of measurement of comnt and their significance in rate 1, currency, length, area, volume, unit size, volume, weight and rate. (Omitted) 2, commonly used time units and their relationships. (Slightly) with a measurement units Zhijian of of poly 1, and of method 2, and poly method 3, and of method and poly method of relationship measurement distance of method 1, and tool measurement 2, and estimates 16, and subject: geometry preliminary knowledge (1)--line and angle review content line, and segment, and Ray, and vertical, and parallel, and angle angle of classification (slightly) 17, and subject: geometry prdge (2)ng to meani--plane graphics review content triangle, and edges shaped, and round, and fan axisymmetric graphics perimeter and arehea combination graphics of area subject : Preliminary knowledge (3)-review of solid content category 1-d shapes are divided into: cylinder and cone 2, column is divided into: cuboid, square 3, cone cone of the features of cuboids and cubes relatimon units of measuremeonship between characteristics of circular cone is slightly solid surface area and volume 1, size 2, table ...和} 程序运行时输入:1 2<回车>,执行后输出结果是什么? (1) 运行结果: (2)结果分析:从键盘上输入12,就是给c1和c2分别赋值1和2,然后通过第7行的运算,n1变为1,n2变为一个两位数:12,十位为1,个位为2。从而输出显示也是12,实现了将字符串转换为多位数。 (2) 字符串转换为多位数的算法如下: #include void main() { char c1,c2,c3,c4; int n1,n2,n3,n4; c1=getchar(); c2=getchar(); c3=getchar(); c4=getchar(); n1=c1-'0'; n2=c2-'0'; n3=c3-'0'; n4=n1*1000+n2*100+n3*10+(c4-'0'); printf(\} 运行结果: relationship, established equivalent relationship 14, and subject: application problem (4)--scores and percentage application problem review content overview answers scores, and percentage application preliminary knowleoblem of key is: according to meaniphing, (1) determine standard volume (units \n in-line solution. Category fraction multiplication word problem score Division applications engineering problem problem XV, a subject: review of the measurement of the amount of capacity, measurement and units of measurement of comnt and their significance in rate 1, currency, length, area, volume, unit size, volume, weight and rate. (Omitted) 2, commonly used time units and their relationships. (Slightly) with a measurement units Zhijian of of poly 1, and of method 2, and poly method 3, and of method and poly method of relationship measurement distance of method 1, and tool measurement 2, and estimates 16, and subject: geometry preliminary knowledge (1)--line and angle review content line, and segment, and Ray, and vertical, and parallel, and angle angle of classification (slightly) 17, and subject: geometry prdge (2)--plane gracs review content triangle, and edges shaped, and round, and fan axisymmetric graphics perimeter and arehea combination graphics of area subject : Preliminary knowledge (3)-review of solid content category 1-d shapes are divided into: cylinder and cone 2, column is divided into: cuboid, square 3, cone cone of the features of cuboids and cubes relatimon units of measuremeonship between characteristics of circular cone is slightly solid surface area and volume 1, size 2, table ...和 (三).若有以下程序 #include void main() { int i,j; int x,y; scanf(\ scanf(\ printf(\ printf(\} 要求给i赋值为10,j赋值为20,则应该怎样从键盘输入数字? 输入i=10,j=20 运行结果如下图所示 (四) 计算定期存款本利之和 设银行定期存款的年利率rate为2.25%,并已知存款期为n年,存款本金为capital元,试编程计算n年后的本利之和deposit。要求定期存款的年利率rate、存款期n和存款本金capital均由键盘输入。 编写的源代码为: #include #include int main() { } float rate,deposit,a; int n,capital; printf(\请输入年利率rate,存款期n,存款本金capital:\\n\scanf(\printf(\年利率rate=%f\\n存款期n=%d\\n存款本金capital=%d\\n\deposit=capital*a; printf(\本利之和deposit为%f\\n\return 0; a=pow(1+rate,n); relationship, established equivalent relationship 14, and subject: application problem (4)--scores and percentage application problem review content overview answers scores, and percentage application preliminary knowleoblem of key is: according, (1) determine standard volume (units \n in-line solution. Category fraction multiplication word problem score Division applications engineering problem problem XV, a subject: review of the measurement of the amount of capacity, measurement and units of measurement of comnt and their significance in rate 1, currency, length, area, volume, unit size, volume, weight and rate. (Omitted) 2, commonly used time units and their relationships. (Slightly) with a measurement units Zhijian of of poly 1, and of method 2, and poly method 3, and of method and poly method of relationship measurement distance of method 1, and tool measurement 2, and estimates 16, and subject: geometry preliminary knowledge (1)--line and angle review content line, and segment, and Ray, and vertical, and parallel, and angle angle of classification (slightly) 17, and subject: geometry prdge (2)ng to meani--plane graphics review content triangle, and edges shaped, and round, and fan axisymmetric graphics perimeter and arehea combination graphics of area subject : Preliminary knowledge (3)-review of solid content category 1-d shapes are divided into: cylinder and cone 2, column is divided into: cuboid, square 3, cone cone of the features of cuboids and cubes relatimon units of measuremeonship between characteristics of circular cone is slightly solid surface area and volume 1, size 2, table ...和 (五). 键盘输入与屏幕输出练习 问题1 要使下面程序的输出语句在屏幕上显示1, 2, 34,则从键盘输入的数据格式应为以下备选答案中的 D) 。 #include main() { char a,b; int c; } scanf(\printf(\A)1 2 34 C)’1’,’2’,34 则应修改程序中的哪条语句?怎样修改? B)1, 2, 34 D)12 34 问题2 在与上面程序的键盘输入相同的情况下,要使上面程序的输出语句在屏幕上显示1 2 34,答:将printf(\改成printf(“%c %c %d\\n”,a,b,c); 问题3 要使上面程序的键盘输入数据格式为1,2,34,输出语句在屏幕上显示的结果也为1,2,34,则应修改程序中的哪条语句?怎样修改 将scanf(\改成scanf(\ 问题4 要使上面程序的键盘输入数据格式为1,2,34,而输出语句在屏幕上显示的结果为'1', '2',34,则应修改程序中的哪条语句?怎样修改? 将 scanf(\ printf(\printf(\ 改成scanf(\ 问题5 要使上面程序的键盘输入无论用下面哪种格式输入数据,程序在屏幕上的输出结果都为'1', '2',34,则程序应修改程序中的哪条语句?怎样修改? 第1种输入方式:1,2,34↙(以逗号作为分隔符) 第2种输入方式:1 2 34↙(以空格作为分隔符) 第3种输入方式:1 2 34↙(以Tab键作为分隔符) 第4种输入方式:1↙ 2↙ relationship, established equivalent relationship 14, and subject: application problem (4)--scores and percentage application problem review content overview answers scores, and percentage application preliminary knowleoblem of key is: according to meaniphing, (1) determine standard volume (units \n in-line solution. Category fraction multiplication word problem score Division applications engineering problem problem XV, a subject: review of the measurement of the amount of capacity, measurement and units of measurement of comnt and their significance in rate 1, currency, length, area, volume, unit size, volume, weight and rate. (Omitted) 2, commonly used time units and their relationships. (Slightly) with a measurement units Zhijian of of poly 1, and of method 2, and poly method 3, and of method and poly method of relationship measurement distance of method 1, and tool measurement 2, and estimates 16, and subject: geometry preliminary knowledge (1)--line and angle review content line, and segment, and Ray, and vertical, and parallel, and angle angle of classification (slightly) 17, and subject: geometry prdge (2)--plane gracs review content triangle, and edges shaped, and round, and fan axisymmetric graphics perimeter and arehea combination graphics of area subject : Preliminary knowledge (3)-review of solid content category 1-d shapes are divided into: cylinder and cone 2, column is divided into: cuboid, square 3, cone cone of the features of cuboids and cubes relatimon units of measuremeonship between characteristics of circular cone is slightly solid surface area and volume 1, size 2, table ...和34↙(以回车符作为分隔符) 将整个程序改成 #include int main() { int a,b,c; scanf(\ printf(\} 三、结论(写本次实验的收获) 本次实验中,重点练习了输入和输出语句的使用,特别是最后一道大题,通过五种不同的方式对程序进行修改、变形,使得输出各种不同的结果,充分体现出了C语言的灵活性。同时今后进行C语言实验时,要学会举一反三,多思考其他不同的方法。 说明:
1. 电子实验报告填写好后,以学生的学号+实验项目名作为该word文件名保存,例
如某学生学号为,姓名为某某,本次实验名称是:实验一 顺序结构程序设计,则本次实验报告的保存文件名为:01某某实验一.doc。 2. 在规定的时间内,学生将本报告提交给实验指导教师。