0

我已经使用静态数组创建了正向差异表,但无法使用动态数组解决它,请帮我解决这个表。

这是静态数组的代码,但我需要动态数组

#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--;
    }


}
4

1 回答 1

0

如何初始化二维数组:

float** farray;
farray = new float*[c];
for (int ind = 0; ind < c; ind++) farray[ind] = new float[r];
于 2017-03-17T17:40:24.613 回答