发布网友 发布时间:2024-10-23 19:08
共3个回答
热心网友 时间:2024-11-09 01:10
代码文本:
#include "stdio.h"
int main(int argc,char *argv[]){
double s;
int m,n;
printf("Enter m & n(int 0<m<=n)...\n");
if(scanf("%d%d",&m,&n)==2 && m>0 && n>=m){
if(n-m>3)
printf("1/%d+1/%d+1/%d+...+1/%d",m,m+1,m+2,n);
else if(m+3==n)
printf("1/%d+1/%d+1/%d+1/%d",m,m+1,m+2,m+3);
else if(m+2==n)
printf("1/%d+1/%d+1/%d",m,m+1,m+2);
else if(m+1==n)
printf("1/%d+1/%d",m,m+1);
else if(m==n)
printf("1/%d",m);
for(s=0.0;m<=n;s+=1.0/m++);
printf(" = %.10f\n",s);
}
else
printf("Input error, exit...\n");
return 0;
}
热心网友 时间:2024-11-09 01:10
#include <stdio.h>
main( void )
{
int m,n;
double t=0;
scanf("%d%d",&m,&n);
if( m <=0 || m > n )
{
printf("input error!" ) ;
return ;
}
while( m<=n)
t+=1.0/m++;
printf("%.10lf\n",t);
return ;
}
热心网友 时间:2024-11-09 01:08
#include <stdio.h>
main()
{
int m,n,i;
double s=0;
scanf("%d%d",&m,&n);
for(i=0;i<=n-m;i++)
s+=1.0/(m+i);
printf("%.10lf\n",s);
}