Whenever I define the parameter i
in the function exam
as an integer it always prints Sum = 0.00
.
I would like to know why it is doing that...
#include <stdio.h>
#include <stdlib.h>
float exam(float i) {
if (i == 0) {
return 0;
} else {
return (i / (i + 1)) + exam(i - 1);
}
}
int main() {
int i;
printf("Enter an integer: ");
scanf("%d", &i);
printf("Sum = %.3f", exam(i));
return 0;
}