求n分之一序列的前n项和
#include <stdio.h>
int main()
{
int N;
int a=1;
float s=0.0;
scanf("%d",&N);
while (a<=N)
{
s=s+1.0/a;
a++;
}
printf("sum = %.6f",s);
return 0;
}
5
sum = 2.283334
Process returned 0 (0x0) execution time : 1.172 s
Press any key to continue.
100
sum = 5.187378
Process returned 0 (0x0) execution time : 2.607 s
Press any key to continue.