您的位置:首页 > 其它

My coding way (1)

2015-10-21 23:41 169 查看

问题 A: 【C语言训练】计算t=1+1/2+1/3+...+1/n

时间限制: 1 Sec 内存限制: 128 MB

题目描述

计算t=1+1/2+1/3+...+1/n

输入

整型变量n

输出

t(保留六位小数)

样例输入

10

样例输出

2.928968

This is my first time using CSDN blog system. If anthing is wrong, please contact me as soon as possible ~

#include <stdio.h>
int main()
{
int n;
double ans=0;
scanf("%d",&n);
for(;n>0;n--)
{
ans+=1.0/n;
}
printf("%.6lf \n",ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: