C语言程序设计试验二.doc

上传人:scccc 文档编号:11941593 上传时间:2021-11-09 格式:DOC 页数:11 大小:120KB
返回 下载 相关 举报
C语言程序设计试验二.doc_第1页
第1页 / 共11页
C语言程序设计试验二.doc_第2页
第2页 / 共11页
C语言程序设计试验二.doc_第3页
第3页 / 共11页
C语言程序设计试验二.doc_第4页
第4页 / 共11页
C语言程序设计试验二.doc_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《C语言程序设计试验二.doc》由会员分享,可在线阅读,更多相关《C语言程序设计试验二.doc(11页珍藏版)》请在三一文库上搜索。

1、电子科技大学计算机学院标准实验报告(实验)课程名称 C语言程序设计电子科技大学教务处制表电子科技大学实验报告学生姓名: 学 号:指导教师:刘勇实验地点: 计算机学院软件 306 室实验日期:年月 日一、实验室名称: 软件实验室二、实验项目名称:程序结构语句应用三、实验学时: 4四、实验原理:使用Turbo C软件(简称TC),在微型计算机上,对其程序进行编辑、编译、连接与运 行。Turbo C是一个集成环境,它具有方便、直观、易用的界面和丰富的库函数。通过上机 练习掌握在 TC 环境下编辑、编译、连接、和运行 C 程序的方法和过程。五、实验目的1、掌握顺序、分支和循环结构各种语句的一般功能和执

2、行过程;2、学会应用各种语句进行编程;3、掌握流程图的一般表示方法;4、掌握结构化程序设计的基本方法;5、掌握数组的定义及其应用。六、实验内容编程实验,完成以下上机内容,调试运行程序并完成报告1)、教材第五章习题 5.8 ;2)、教材第四章习题 4.4 (用 if else 语句实现);3)、编写一个计算器程序,要求用户输入运算数和四则运算符, 输出计算结果 (用 switch语句实现);4)、编写一个程序输出 1000 以内的所有素数(用 for 语句实现);5)、教材第四章习题 4.14 (用 do while 语句实现);6)、教材第五章习题 5.7 ;7)、教材第五章习题 5.9 ;七

3、、 实验器材(设备、元器件):pc硬件要求:CPU PII以上,64M内存,1OOM硬盘空间即可。软件要求:DOS3.0 以上/Windows98/Me/XP/NT/2000。八、实验步骤:实验编程与运行结果 输入一串字符,直到读到句号为止,记录下这串字符中既不是字母也不是数字的所有字 符,然后把这些字符按与输入相反的次序输出。程序文件名为5_9.c,源程序清单如下:#i ncludemai n()char s50,ch;int cou nt=0,i;prin tf(Please in put the str in g:);dosca nf(%c, &ch);if(!(ch=0 )&(ch=A

4、)&(ch=a)&(ch=0;i_)prin tf(%c,si);prin tf(n);运行结果:E:TURB0C2TTCO5_9Please input the string: f&x*)(E:TURBOC2TTCO_编写程序计算(用if else 语句实现)i乞55 i叮0i 101 +2 + +iresult =100 _i _(i -1) 一-1.2i程序文件名为D2C1.C,源程序清单如下:#i ncludemai n()int i,j,result=0;prin tf(Please in put a in teger:);sca nf(%d,&i);if(i=5)for(j=1;j

5、10)result=i*i;elseresult=100;for(j=i;j=1;j-) result=result-j;prin tf(result=%dn,result);_运行结果:E:TUflBOC2TTCOd2cl Please input a int result=6E:TURBOC2XTTCOd2cl Please input a integer:6 result=79E:TURBOC2TTCOd2clPlease input a integer:11 result=121E:TURB0C2TTCC_switch 编写一个计算器程序,要求用户输入运算数和四则运算符,输出计算结果(

6、用 语句实现)。程序文件名为testf.c,源程序清单如下:mai n()float x,y;char ch;prin tf(I nput two real n umbers and an operator: n);sca nf(%f %f %c, &x,&y, &ch);switch(ch)case +:pri ntf(x+y=%fn,x+y);break;case -:pri ntf(x-y=%fn,x-y);break;case *:pri ntf(x*y=%fn,x*y);break;case /: if(y!=0.0)pri ntf(x/y=%fn,x/y);elsepri ntf(

7、x can not be divided by 0.0n);break;default: prin tf(i nvalid opratorn);_运行结果:E:TURBOC2xTTCOtestfInput tuo real numbers and an operator: 5 6 +x*y=ll-00Q000E:TIIRBOC2TTCOtestfInput two real nunbers and an operator: B 4 -xy=4,000000E:TURB0C2XTTCC)testfInput tuo real numheFS and &n operator: 9 *x*y=?2.

8、000000E=xTURB0C2xTTCCtestfInput tuo real nunbers and an operator:20 2 /x/y=10.000SB0E:TUHBOCZxTTCCtestfInput two real nunbers and an operator: B 0 /x can not ba divided by 0.0|E:TURBOC2TTCC编写一个程序输出1000以内的所有素数(用 for语句实现)程序文件名为D2C3.C,源程序清单如下:#i nclude#in clude#defi ne N 1001mai n()int i,j;int flag;for

9、(i=2;i9773787797S09811021B23827829B39853857859B6377981曲388790791191992?93?941947953967971977983991997E:TURBOC2TTCO 编写一个程序,找出被2, 3, 5整除时余数均为1的最小的10个自然数(用do while语句实现)。程序文件名为4_15.c,源程序清单如下:#i ncludemai n()int i=1;static cou nt=1;prin tf(number can by 2,3,5 divde exactly is: n);while (cou nt=10)if(i%2=

10、1)&(i%3=1)&(i%5=1)cou nt+;prin tf(%d ,i);i+;_运行结果:E:TUBB0C2ITCO4_15umber can by 2r3,5 diude exactly is: 1 31 61 91 121 151 181 211 241 2?1 E:TURBOC2TTCO_ 编写一个程序,输入n个整数,求这n个数中的最小值以及最小值元素在这n个数中的排列位置。程序文件名为5_7.c,源程序清单如下:#i ncludemai n()int n ,data20;int i;in t mi n=32767,locat;prin tf(Plase in put N:);

11、sca nf(%d,&n);prin tf(please in put %d in tegers: , n);for(i=0;i n ;i+)sca nf(%d, &datai);if(datai57Plase input N: 5please input 5 integers: 8 3 12 45 ? nin: 3,posit ion: 2EATUfflW2IICC.编写一个程序,求一个二维矩阵的转置矩阵。 程序文件名为5_9.c,源程序清单如下:#i ncludemai n()int m1010;int i,j,temp;prin tf(Please In put 4*4: n);for(i=0;i4;i+)for(j=0;j4;j+)sca nf(%d,&mij);for(i=0;i4;i+)for(j=i;j4;j+)temp=mij;mij=mji;mji=temp;printf(Chenge of: n);for(i=0;i4;i+)for(j=0;j5九、总结及心得体会:十、对本实验过程及方法、手段的改进建议:报告评分:指导教师签字:

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1