使用动态数组使用 c++ 的前向差异表
Forward Difference table with c++ using 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--;
}
}
如何初始化二维数组:
float** farray;
farray = new float*[c];
for (int ind = 0; ind < c; ind++) farray[ind] = new float[r];
相关文章:
- std::向量与传递值的动态数组
- 在c++中用vector填充一个简单的动态数组
- 输出没有重复元素的动态数组(收缩数组)C++
- 正在插入动态数组
- 如何在动态数组上使用搜索函数
- C++ 动态数组每次添加时将大小增加 1 - 错误
- 静态数组的自由动态数组
- 在 c++ 中对类中的 c 字符串动态数组进行排序的最佳方法是什么?
- 使用 thread 类在 C++ 中构造线程的动态数组时出错
- 如何为 c++ 的不同变量类型的结构元素创建动态数组?
- C++ 使用存储在动态数组中的文本文件中的数据查找模式
- 当我使用自定义类型创建动态数组时,即使使用字符串,它似乎也不起作用
- 为什么 c++ 动态数组的大小没有改变?
- 具有自定义构造函数 (C++) 的类型的动态数组分配
- 指针的 C++ 动态数组 - 何时需要使用它?
- 删除动态数组时未定义标识符
- 哈希映射使用 nullptr c++ 初始化节点的动态数组
- 如何将字符串和整数读取到两个单独的动态数组中的程序编写?
- 动态数组的 C++ 重载加运算符
- 基于数组的列表 - 动态数组创建时出错