好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

C语言程序设计-实验3.pdf

138页
  • 卖家[上传人]:缘***
  • 文档编号:336602287
  • 上传时间:2022-09-22
  • 文档格式:PDF
  • 文档大小:13.72MB
  • 文本预览
  • 下载提示
  • 常见问题
    • 摩甲科技火穿课 程 实 验 报 告课程名称:C语言程序设计_ _ _ _ _ _ _ _ _ _专业班级:信息安全班学 号:_ _ _ _ _ _ _ _ _ _ _ _ _姓 名:_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _指导教师:_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _报告日期:2014年6月1 6日计算机科学与技术学院目录1实验概述.12第一次实验.12.1 实验目的.12.2 实验内容.12.3 实验小结.13 第二次实验.13.1 实验目的.1 13.2 实验内容.1 13.3 实验小结.1 64 第三次实验.1 64.1 实验目的.1 64.2 实验内容.1 64.3 实验小结.2 05第四次实验.2 05.1 实验目的.2 05.2 实验内容.2 05.3 实验小结.2 46第五次实验.2 46.1 实验目的.246.2 实验内容.2 46.3 实验小结.2 77第六次实验.2 87.1 实验目的.2 87.2 实验内容.2 87.3 实验小结.348第七次实验.358.1 实验目的.359.2 实验内容.354.3 实验小结.389附:第二章基础实验.389.1实验2.1 熟悉C 语言程序的开发环境.389.2 实验2.2 表达式和标准输入与输出实验.489.3 实验2.3 流程控制实验.5 59.4 实验2.4 函数与程序结构实验.6 89.5实验2.5 编译预处理实验.8 09.6实验2.6 标准库及用户自定义库实验.8 99.7 实验2.7 数组实验.9 29.8实验2.8 指针实验.1 069.9实验2.9 结构与联合实验.1 1 99.1 0 实验2.1 0 文件实验.1 311 0 实验总结.1 3-1 34-参考文献.1 351 实验概述本实验共包含两大部分:第一大部分是c语言上机实验部分;第二大部分是 C语言与课程设计一书中第二单元基础实验部分,又分为熟悉C语言程序的开发环境、表达式和标准输入与输出实验、流程控制实验、函数与程序结构实验、编译预处理实验、标准库及用户自定义库实验、数组实验、指针实验、结构与联合实验、文件实验等十个小节。

      每个小实验又包含实验目的、实验内容、源代码呈现以及调试过程及运行结果进行该次实验的主要目的是熟练掌握C语言基础知识以及熟悉编程和编程工具Visual C+6.0和Code2 第一次实验2.1 实验目的1 .学习和掌握语言中,基本的输入输出函数的使用方法2 .掌握顺序程序的设计方法3.进一步掌握调试工具的使用方法4.掌握printf中转义字符n的用法5.掌握赋值语句的用法6.掌握算术表达式、赋值表达式的计算7.掌握数学函数的使用2.2 实验内容(-)设计一个程序,在字符模式下,以某个字符拼出“王”汉字图形,显示输出1 .实验源代码#i n c l u d e v o i d m a i n(v o i d)p r i n t f Cp r i n t f Cp r i n t f(p r i n t f(p r i n t f(p r i n t f Cp r i n t f(O O O O O O O O O O O X n );0 n);0 n);O O O O O O O O O O O X n );0 n);0 n);00000000000 n n n n n n n n );2 .程序的调试及运行结果-1 -(二)输入一个华氏温度,要求输出摄氏温度。

      公式为c=5/9*(f-32)1.实验源代码#includevoid main(void)float a,c;printf(please input Fahr:n);scanf(%f,&a);c=5.0/9*(a-32.0);printf(Cel=%fn,c);2.程序调试及运行结果please input F ahr:-2 0C e l-2 8.8 8 8 8 8 9Press any key to continueplease input F ahr:0C e l-1 7.7 7 7 7 7 8Press any key to cont inueplease input F ahr:4 4.8C el-7.1 1 1 1 1 1Press any key to continue(三)设计3 种算法,完成交换整型两个变量值的程序2-实验源代码#include void main(void)(int a,b,tmp;printf(Please input two integers:n);scanf(%d%d,&a,&b);tmp=a;a=b;b=tmp;printf(%d,%dn,a,b);2、#include void main(void)(int a,b;printf(Please input two integers:n);scanf(%d%d,&a,&b);a A=b;b 八=a;a A=b;printf(a=%d,b=%dn,a,b);3、#includevoid main(void)int a,b,m;printf(Please input two integers:n);scanf(%d%d,&a,&b);m=a+b;a=m-a;b=m-b;printf(%d,%dn,a,b);2.程序调试及其运行结果 程序1:-3-丁 c.l i c s.u z u x 0 x i o _ x u e u u y i e b e o J请输入两个整数:-3党人的两个整数,交换值之后是:-8,-3Press any key to continue请输入两个整数:13翁人的两个整数,交换值之后是:2,13Press any key to continue请输入两个整数:0络入的两个整数,交换值之后是:17,0Press any key to cont inue程序2:Please input two in teg ers:-3”0.b0-3Press any key to continuePlease input two in teg ers:-1?25a25,bT 7Press any key to continuePlease input two in teg ers:543768290873651a-90873651,b-5437682Press any key to cont inue程序3:请输入两个整数:22交换后的两个螭是,2,2Press any key to continue情输入两个整数:13568交换后的两个整数是,568.13Press any key to cont inue请输入两个整数:-12354398763交换后的两个整数是i 98763,-123543Press any key to continue-4-(四)设计一个程序,完成如下功能:输出一个三位数,将它反向输出。

      如输入12 7,输出7211.实验源代码#includeint main(void)int a,b,c,d,e;printf(please input a three-digit numberin);scanf(%d,&a);b=a/100;c=(a-100*b)/10;d=(a-100*b-10*c);e=100*d+10*c+b;printf(%dn,e);p lease input a th n e e-d ig it number:673376P ress any key to con tin ue(五)设 计 2 种完成计算MAXx,y,z的程序1.实验源代码1、#includeint main(void)float a,b,c,m;printf(please input a b c:n);scanf(%f%f%f,&a,&b,&c);if(ab)if(ac)m=a;else m=c;else if(bc)m=b;else m=c;-5-printf(max=%fn,m);2、#includeint main(void)float a,b,c,m;printf(please input a b c:n);scanf(%f%f%f,&a,&b,&c);if(ab)if(ac)m=a;else m=c;else if(bc)m=b;else m=c;printf(max=%fn,m);2.程序调试及运行结果please input a b c:-7.801 2max-1 2.0 0 0 0 0 0Ptess any key to continueplease input a b c:-1-2Tmax*-1.0 0 0 0 0 0Press any key to continueplease input a b c:-21 71 7max-1 7.0 0 0 0 0 0Press an9 key to continue-6-please input a b c:8 78 78 7max=8 7.0 0 0 0 0 0Press any key to continue(六)设计一个程序,完成计算3 个数的居中数。

      1.实验源代码#includeint main(void)float a,b,c,m;printf(please input a,b,c:n);scanf(%f%f%f,&a,&b,&c);if(abc|cba)m=b;else if(acb|bca)m=c;else m=a;printf(the middle is2.程序调试及实验结果please input a,b,c:2 192 3 4the middle is 2 1.0 0 0 0 0 0Press any key to continueplease input a,b,c-2 30.2 17the middle is 0.2 1 0 0 0 0Press any key to continueplease input0-9 5the middle is 0.0 0 0 0 0 0Press any key to continue(七)设计计算一元二次方程的根的程序1.实验源代码#include#include int main()double a,b,c;double rst1,rst2;double det;-7-printf(please input the arguments of the equation:n);scanf(%lf%lf%lf,&a,&b,&c);if(a=0)printf(rst=%1f,-c/b);else(det=b*b-(4*a*c);if(det0(有两个不同根)情形:please input the arguments of the equation:2-1 05rstl=4.4 3 6 4 9 2,rst2 =0.5 6 3 5 0 8Press any key to continue(A)根据任意三角形的面积公式(海伦公式):S=Vp(p-a)(p-b)(p-c),其中,p=(a+b+c)/2,a.b.c为三角形三边,设计一个程序计算任意三角形的面积。

      1.实验源代码#include#includeint main(void)float a,b,c,s,t,m;printf(please input three edge of triangle:n);scanf(%f%f%f,&a,&b,&c);if(a+b=c|a+c=b|b+c 掌握复合语句、if语句、switch语句的使用,熟练掌握for、while、do-while三种基本的循环控制语句的使用,掌握重复循环技术,了解转移语句与标号语句2、熟练运用for、while、do-while语句来编写程序3、联系转移语句和标号语句的使用3.2实验内容9.设计一个计算个人所得税的程序1.实验源代码#includevoid main(void)float a,。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.