高级语言程序设计实验报告
课程名称
高级语言 程序设计
实验项目
循环结构编程练习
实验项目类型
验
证
演
示
综 合
设
计
指导教师
李养群
成绩
V
一、实验目的
1、正确的使//设置循环语句的初始值为1,最后的值n {
sum+=a/i;//累加求和 a=-a;//设置每项的符
printf("%f\n",sum); return 0;
}
试验结果:
g *C:\Progra> FilesMicrosoft Visual Studio\ByProjects\5
晴输入项数3
Press any key to continue —
g% *C:\Progra> Files\Bicrosaft Visual Studio\ByProjects\5
隋输入项数5
Press any key to continue —
-SN-1l<10-6,求和并且输出n的项数
#include<>
#include<>
void main()
{
int n=2;
float temp=1,sum=1;
do
{ _
temp=-temp/n;//每一项数字的表示 sum+=temp; n=n+1; } while (fabs(temp)>=1e-6);//设置循环结束的条件是当sum的绝对值小于10—6 printf("sum=%f\n",sum);
printf("n=%d\n”,n);
}
运行结果:
匚 *D:\09006512\33\Debug\33. exe
632120
n=ll
Press any key to continue
【题2】
,判断是否是质数,输出判断结果
#include<>
main()
{
int m,n;
scanf("%d”,&m);
for(n=2;n<m;n++)
{
if(m%n==0) //素数的基本判断条件是不存在1和他自身以外他可以整除的数
{
printf("%d 不是素数”,m);
return;
}
}
printf("%d 是素数”,m);
}
运行结果:
g *C: \Progra> Files\licrosoft Visual StudioMyPro ject
M是素数P,ess any key to continue
e *C:\Progra> Files\Bicrosoft Visual Studio\MyProjects\555\Debi
5的不是素数PEesJJ any key to continne —
,变量x不再是由键盘读入,是规定范围(a,b)里面 的任何数,变量a和b在程序运行的时候由键盘输入
#include<>
main()
{
int n,i;
int a,b;
printf("你输入的查找范围是:,
scanf("%d %d",&a,&b);
for(i=a;i<b;i++)
{
for(n=2;n<i;n++)
if(
c实验报告循环1 来自淘豆网m.daumloan.com转载请标明出处.