调和级数不等式
对指定的正数x ,y (2<x<y),试求满足下面调和级数不等式的正整数m的取值范围:x <1 + 1/2 + 1/3 + 1/4 + 1/5 ....... + 1/m < y
#include < stdio.h>
void main()
{
long c ,d , m ;double x,y ,s;
printf (" 请输入正整数 x, y ( 2 < x <y ):“);
scanf ("%lf , %lf", &x , &y );
m = 0; s = 0;
while( s <= x)
{
s =s+ 1.0/(++m);
c = m;
}
do {
s = s + 1.0/ (++m)
while(s < y)
{
d = m - 1;
}
printf("满足不等式的解为 : %ld<= m <= %ld \n ", c ,d);
return 0;
}
其中 do{
s= s+1.0/(++m);
}
while(s < y);
{
d = m - 1;
}
我在书上找的,说是循环求和探索m的上确界d,但我不是很明白,m-1了就是探索m的上确界。
#include <stdio.h>
void main()
{
int x,y;
long c,d,m;
double s;
printf ("请输入正整数x,y(2<x<y),输入格式为x,y:");
scanf ("%d,%d",&x,&y);
m = 0; s = 0;
while(s<=x)
{
s=s+1.0/(++m);
c=m;
}
do{
s=s+1.0/(++m); //累加,直到某个m使得和刚超过y为止,所以结果m要减掉1
}while(s<y);
d=m-1;
printf("满足不等式的解为:%ld <= m <= %ld \n ",c,d);
return;
}
页:
[1]