My aim is to show that the armonic series diverges, by showing that it's bigger of any given real number b
If you consider b=2 as argument of NSA the while cycle should do four iterations and then return s=4. Well...
it doesn't. What's the problem?
#include<stdio.h>
int NSA(float b){
int i=1;
int s=0;
float sum=0;
while(1){
sum+=(1/i);
s=s+1;
if(sum>=b)
break;
else
i=i+1;
}
return s;
}
int main() {
float a;
int m;
printf("Choose a real number: ");
scanf("%f",&a);
m=NSA(a);
printf("The minimum n for which the armonic series is equal to %f is %d\n ",a,m);
}