hi, after a long time been posting in this forum.I am trying to manipulate newtons divide difference formula ,actually like this see here
but in a different manner .but my code is not working.i am getting disgusting values in my table.can any one please check the errors and tell me what it is .my code is like this.Thanks !!!!!

    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    int main()
    {
    int x[10],p,i,n,m,k,j;
    float y[6][5];
    printf("how many numbers?");
    scanf("%d",&n);
    for(i=0;i<n;i++){
    scanf("%d",&x[i]);
    }
    i=0;
    j=0;
    while(j<n){
    scanf("%lf",&y[j][i]);
    j++;
    }
    for(i=0;i<n;i++){
    printf("x[%d]=%d",i,x[i]);
    }
    i=0;j=0;
    printf("\n");
    while(j<n){
    printf("y[%d][%d]=%lf",j,i,y[j][i]);
    j++;
    }
    printf("\n");
    k=0;
    m=1;
    for(i=1;i<n;i++){
    for(j=0;j<n-i;j++){
    y[j][i]=((y[j+1][i-1]-y[j][i-1])/(x[k+m]-x[k]));
    k++;
    }
    k=0;
    m=1+m;
    }
    printf("\n");
    for(i=0;i<n-1;i++){
    for(j=0;j<n-i;j++){
    printf("y[%d][%d]=%lf",j,i,y[j][i]);
    printf("\n");
    }
    }
    getch();
    } 

Recommended Answers

All 3 Replies

You don't have to double post. If people were here and didn't reply they have nothing to say. If they weren't yet here and now see two posts from you they may be put off. It isn't as if your post had fallen off the front page of this forum...

You start of by providing an example and then say: "I'm not doing it that way" but don't indicate how your way is (or should be) different. I also do know what disgusting values mean. I run your code and get all 0.00000 which seems fairly benign to me.

Are there expected inputs and outputs you want to see?

if you visit the link i have given ,you can see the process how the made the table is like

 for(i=1;i<n;i++)


     {
        k=i;
        for(j=0;j<n-i;j++)
        {
         y[i][j]=(y[i-1][j+1]-y[i-1][j])/(x[k]-x[j]);
         k++;
        }
      }

but i wanted to do the similar thing in this form

 k=0;
m=1;
for(i=1;i<n;i++){
for(j=0;j<n-i;j++){
y[j][i]=((y[j+1][i-1]-y[j][i-1])/(x[k+m]-x[k]));
k++;
}
k=0;
m=1+m;
}

but it is not working,i've done my paper works on it but cant find what the mistake is?????

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.