Reputation: 9
Please I really need help. I keep running my program but no matter what loop I try or intervals I put, program just keeps running forever. Here's the code
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define w 2004
#define n 10
float fn(float x)
{
exp(-(w*(x*x)));
return exp(-(w*(x*x)));
}
main()
{
int i;
float a=-1,b=1,s,y,h;
s=0;
done:
n+10;
if(n<=100){
i=1;
do{
s=s+fn(a+i*h);
i++;
continue;
}
while(i<n-1);
h=(b-a)/n;
y=(fn(a)+fn(b)+2*s)*h/2;
printf("\nThe value of y is=%0.4f\n", y);
goto done;
}
return 0;
}
Upvotes: 0
Views: 58
Reputation: 12262
Your question lacks vital information. However, something like
while(i<n-1);
cannot be sane. None of the variables changes inside the loop, so it will loop forever (wasn't that what you noticed?).
Upvotes: 1