1. ## Floating point error

Code:
#include<stdio.h>
#include<conio.h>
void main()
{
float x[20],fx[20],p[20]={1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0};
int i,n,j;
float a,b;
float z;
float sum=0.0;
clrscr();
printf("Enter the number of interpolating points ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter the values of x and f(x) ");
scanf("%f %f",x[i],fx[i]);
}
printf("\nEnter the value at which you wish to find the values of Lagrangee's polynomial ");
scanf("%f",&z);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
j++;
a=(z-x[i+j]);
b=(x[i]-x[i+j]);
p[i]=p[i]*(a/b);
}
}
for(i=0;i<n;i++)
{
sum=sum+p[i]*fx[i];
}
printf("%f",sum);
getch();
}
This program is showing no compilation and linking error but showing
"Floating point errorivide by 0
Null pointer assignment"
Why is it so?

2. use int main() not void main()

3. scanf("%f %f",x[i],fx[i]);

scanf needs pointers to variables, like

scanf("%f",&z);

4. After correcting the scanf problem it is still showing the error "Floating point error divide by 0"

5. Use a debugger to help you find the problem. Since the error message mentions division by zero, put a break point around the places where division is performed.

7. I doubt you want x[i+j] but x[j] instead -- you're treating j as a proper index in the for loop, not the delta between two indices.

8. thx to all.I have finally cracked it...

9. Originally Posted by ankitsinghal_89