0

i have created forward difference table by using static array but can't solve it by using dynamic array please help me to solve this table.

This is the code with static array but i need it with dynamic array

#include<iostream>

int main()
{
    inti,noOfDifferenceColumns;
    //j is no of columnds. Initially it is 2. One for x, and other for f(x).
    int j=2;
//std::cout<< "Hello World!\n";
//std::cout<<"Hello Hello";
    std::cout<<"Enter no of values for x: ";
    std::cin>>i;
    std::cout<<"Enter no of difference tables to be created: ";
    std::cin>>noOfDifferenceColumns;
    j+=noOfDifferenceColumns;
    floatarray[20][20];
    //Entering values of x 
    std::cout<<"Enter values for x: \n";
    for(int a=0;a<2;a++)
    {
        for(int b=0;b<i;b++)
        {
            `enter code here`std::cin>>array[b][a];enter code here
            `enter code here`std::cout<<"\n";

        }
        if(a==0)std::cout<<"Enter value for f(x): \n";

    }
    std::cout<<"\nPrinting values: ";
    std::cout<<"\nPrinting x and f(x): ";
    //condition is c<2 as the outer loop will run twice. Once to print x and then to print f(x)
    for(int c=0;c<2;c++)
    {
        if(c==0) std::cout<<"X"<<"\n";
        elsestd::cout<<"F(X)"<<"\n";
        for(int d=0;d<i;d++)
        {
            std::cout<<array[d][c]<<"\n";
        }
    }
    std::cout<<"Printing Difference Tables: \n";
    int g=i-1; 
    for(int e=2;e<j;e++)
    {
        std::cout<<"Printing Difference Column: "<<e-1<<"\n";
        for(int f=0;f<g;f++)
        {

            array[f][e]=array[f+1][e-1]-array[f][e-1];
            std::cout<<array[f][e];
            std::cout<<"\n";
        }
        g--;
    }


}

1 Answers1

0

How to initialize the two-dimensional array:

float** farray;
farray = new float*[c];
for (int ind = 0; ind < c; ind++) farray[ind] = new float[r];
user3811082
  • 218
  • 1
  • 7