计算机技术基础实验,《计算机技术基础》实验报告8.doc

塔里木大学 信息工程学院

PAGE 7

塔里木大学计算机基础课程实验报告

课程名称:

计算机技术基础

任课教师:

杨全丽

机 房:

计算机编号:

实验日期:

实验成绩:

实验班级:

机械电子工程14-2

学生姓名:

韩继凯

实验名称:

实验八 函数一

实验目的:

1.掌握C语言函数的定义方法、函数的声明及函数的调用方法。

2.了解主调函数和被调函数之间的参数传递方式。

实验步骤与内容:

程序填空、编写程序段

在sum函数中,根据整型形参m,计算如下公式的值。

1 1 1 1

y = + + + …… +

100*100 200*200 300*300 m*m

例如,若形参 m = 2000,则程序输出:

The result is: 0.000160。

#include

/************Fill in the blanks************/

sum(int m)

{ int i;

double y,d;

/************Fill in the blanks************/

;

for(i=100;i<=m;i+=100){

d = (double)i * (double)i ;

y += 1.0/d;

}

/************Fill in the blanks************/

return( );

}

main( )

{ int n = 2000 ;

printf("\nThe result is: %lf\n",sum(n));

}

运行结果:

求出以下分数序列的前n项之和。

2 3 5 8 13 21

┄┄ , ┄┄ , ┄┄ , ┄┄ , ┄┄ , ┄┄ , ……

1 2 3 5 8 13

例如,若n = 5,则应输出:8.391667。

#include

/************Fill in the blanks************/

Double sum(int n)

{ int a,b,c,k;

double s;

/************Fill in the blanks************/

S=0 ;

a=2;

b=1;

for(k=1;k<=n;k++){

s=s+(double)a/b;

c=a;

/************Fill in the blanks************/

A=c+b ;

b=c;

}

return s;

}

main()

{ int n=5;

printf("\nThe value of function sum is: %lf\n",sum(n));

}

运行结果:

计算1!+2!+3!+...+n!。

#include

long count(int n)

{ int i;

long sum=0,p=1;

/************Fill in the blanks************/

for( i=1;i<=n;i++ )

{

p=p*i;

/************Fill in the blanks************/

Sum=sum+p ;

}

return(sum);

}

main( )

{

int n;

printf("计算1!+2!+3!+...+n!\n请输入n的值(3

/************Fill in the blanks************/

Scanf(“%d”,&n) ;

printf("1!+2!+...+%d!=%ld\n",n,count(n));

}

运行结果:

计算两个双精度数的和的平方根。

例如,若输入:23.18,32.4721,则输出:z=7.460034。

#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值