苏州霍尼韦尔测试:求解c语言编程题:求满足不等式1+1/2+1/3+...+1/n>15求最小的n值并输出

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 11:38:14

#include<iostream>
using namespace std;
void main()
{
long int n;
double sum;
n=1;
sum=0.000000;
do
{
sum=sum+(float)1/n;
n++;
}
while(sum<=15);
cout << n <<endl;
cout << sum ;
}
所以总共是:1835422次!我这个是C++编写的!希望你改成C语言可以了!呵呵!

#include <stdio.h>

void main()
{
int n,s;
for(n=1,s=0;s<=15;n++)
s=s+1/n;
printf("%d\n",n);
}

这是数学问题,不是C问题, 把你的数学学好先,程序上没有技术困难

我建议用 do while 循环