- 247
- 0
- 约2.73千字
- 约 7页
- 2021-03-08 发布于天津
- 举报
-实验3循环结构程序设计
学号: 姓名 实验日期:
实验目的和要求
熟练掌握利用 while、do-while、for语句实现循环结构的方法。
掌握循环结构和选择结构嵌套的设计方法及多重循环的设计方法;
掌握控制语句 break和continue语句的使用方法。
掌握循环结构流程图的表示方法,能根据流程图编制程序。
进一步掌握跟踪调试程序的方法。
实验内容
实验指导书中的实验四的“基础部分”和“增强部分”题目
三、实验步骤及结果
【基础题】:Ex4-1请在下面分别插入改正错误后的源程序代码及运行成功时 的画面:
源程序代码:
请在此粘贴修改后正确的程序代码。
#in cludestdio.h
#in cludemath.h void mai n()
{
int s=1, n=1; float t=1,pi=0;
while (fabs(t)=1e-4) { pi=pi+t; n+=2;
s=-s; t=s*1.0/n;
} pi=pi*4;
prin tf(pi=%f\n,pi);
}
运行结果:
请在此粘贴本程序运行成功时的截图
700800; — :
*includestdio.h llincludeiwdth ?h, void nain() int s*1tn*1; float t-1vpi-0;
while (fabs(t)-1e-4) { pi*pi*t; n**2;
S*S ;
t-S*1.0/n;
printf(pi \ntpi);
D:\VC + + + + \M icrosoft ViI Studio\MyProjpct^\1 700200224 s\Debug\1700200224 豆ex貳
Ex4-2请在下面分别插入完整填空后的源程序代码及运行成功时的画面: 源程序代码:
请在此粘贴填空后正确的程序代码。
#in cludestdio.h
void mai n()
{
int c;
while ((c=getchar())!=\n)
{
if(c==A||c==a)
c+=2;
else if(c==y||c==Y||c==z||c==Z)
c=c-24;
prin tf(%c,c);
}
putchar(\n);
}
运行结果:
请在此粘贴本程序运行成功时的截图
13
ttincludestdio ?h void Rain()
while ((c?getchar())T?*\n*
c*-2;
p1sp if(c = = *y* c*c-24;
putchar(\n *);
1700200224 n*D:\VC + + +
1700200224 n
*D:\VC + + + +\Microsoft StudioXI*
【增强题】:Eh4-1请在下面分别完成本题的流程图、
【增强题】:Eh4-1请在下面分别完成本题的流程图、
程序代码及运行结果的
画面:
程序流程图:
请在此绘制或粘贴实现本题的程序流程图。
源程序代码:
请在此粘贴完成本题的程序源代码。
#in elude stdio.h
int mai n(void) {
int n;
int i;
int curre nt;
int n ext;
int twoaway;
printf(您需要斐波那契数列的前几项?请输入: );
scanf(%d, n);
if (n =0)
prin tf(请输入正整数! \n);
else {
printf(前%d项斐波那契数列为:\n, n);
n ext = curre nt = 1; for (i=1; i =n; i++) {
prin tf(%d\t,curre nt);
if (i%4==0) pri ntf(\n);
twoaway = curre nt+n ex t;
curre nt = n ext;
n ext = twoaway;
}
}
}
运行结果截图:
请在此粘贴本程序运行成功时的截图
I r
IB
N £ r 1 c 1 u d _Fi
int: ir ( vol d J
i t it
int i ;
ini cot -
int: n?xt::
ri 1 t *mi ;
M In 密初斷養滅那饕教列的 MJLlffi? i ■細入, ;
. Ku );
If (n-a)
pr Fit输入正 *2? ! 5):
pr- int 歹M 为 t \n** ?n):
fit4xt — curi*nt — T ;
f- or* ( i ? 1 ; 1 ; i ? ? J {
print *curr^nt ):
1 ¥ t 直*臨pr int (**Xn** J ;
t — cut-rt*it :
c■ nt*xt ;
nt^x t ▼ t wtiuwuy i
Eh4-2请在
原创力文档

文档评论(0)