#include <stdio.h>
int main()
{
int n;
int i;
double sum = 0.0;
scanf("%d", &n);
for ( i =1; i <= 10; i++){
sum += 1.0/i;
}
printf("f(%d)=%f\n", n, sum);
return 0;
}
#include <stdio.h>
int main()
{
int n;
int i;
double sum = 0.0;
int sign = 1;
scanf("%d", &n);
for ( i =1; i <= 10; i++){
sum += sign*1.0/i;
sign = -sign;
}
printf("f(%d)=%f\n", n, sum);
return 0;
}
或者
#include <stdio.h>
int main()
{
int n;
int i;
double sum = 0.0;
double sign = 1.0;
scanf("%d", &n);
for ( i =1; i <= 10; i++){
sum += *1.0/i;
sign = -sign;
}
printf("f(%d)=%f\n", n, sum);
return 0;
}