I am trying to make a simple program that finds the sum of 1 + 1/2 + … + 1/n. However, I have stumbled upon an interesting issue: this for loop works with int but not with double.
double num, result = 1;
double main(){
printf("Input a number: ");
scanf("%f", &num);
for (double i = 1; i < num; i++)
{
result += 1/i;
}
printf("Result: %f", result);
return 0;
}
After replacing every int and %d with double and %f, the loop gets skipped and I cannot figure out why. Does anyone have an explanation for this?