参考代码:
#include
int main()
{
int i, n;
double s = 0.0;
scanf ("%d", &n);
for (i = 1; i <= n; ++i){
s += 1.0/(double)i;
}
printf ("%f\n", s);
return 0;
}
#include
int main(void) {
double sum = 0.0;
int n, i;
scanf("%d", &n);
for (i = 1; i <= n; ++i)
sum += (double)i/n;
printf("%.2f\n", sum);
return 0;
}
VC还是纯c