将阵列的元素变为结构
taking the elements of array whitin a structure
这是我的代码,因为您可以看到我使用了结构数组。问题是我应该如何直接将数组元素直接获取?您可以在下面查看执行之前如何给出程序的元素。
任何帮助都将被申请。
#include<iostream>
#include<math.h>
using namespace std;
struct Data
{
int x, y;
};
double interpolate(Data f[], int xi, int n)
{
double P = 0;
for (int i = 0; i<n; i++)
{
double p= f[i].y;
for (int j = 0;j<n;j++)
{
if (j != i)
p =p*(xi - f[j].x) / (f[i].x - f[j].x);
}
P += p;
}
return P;
}
int main()
{
Data f[] = { { 0,2 },{ 1,3 },{ 2,12 },{ 5,147 }};
cout << "Value of f(3) is : " << interpolate(S, 3, 4) << endl;
system("pause");
return 0;
}
#include<iostream>
#include<math.h>
using namespace std;
struct Data
{
int x, y;
};
double interpolate(Data f[], int xi, int n)
{
double P = 0;
for (int i = 0; i<n; i++)
{
double p= f[i].y;
for (int j = 0;j<n;j++)
{
if (j != i)
p =p*(xi - f[j].x) / (f[i].x - f[j].x);
}
P += p;
}
return P;
}
int main()
{
int input[8];
cout << "Enter first value: n";
cin >> input[0];
cout << "Enter second value: n";
cin >> input[1];
cout << "Enter third value: n";
cin >> input[2];
cout << "Enter fourth value: n";
cin >> input[3];
cout << "Enter fifth value: n";
cin >> input[4];
cout << "Enter sixth value: n";
cin >> input[5];
cout << "Enter seventh value: n";
cin >> input[6];
cout << "Enter eighth value: n";
cin >> input[7];
Data f[] = {{input[0], input[1]}, {input[2], input[3]}, {input[4], input[5]}, {input[6], input[7]}};
cout << "Value of f(3) is : " << interpolate(f, 3, 4) << endl;
system("pause");
return 0;
}
相关文章:
- 使用不带参数的函数访问结构元素
- 访问类lintalizer列表中的结构元素
- 如何为 c++ 的不同变量类型的结构元素创建动态数组?
- 结构元素名称要 cout?
- C++结构元素(成员变量)的数量
- 如何在类中声明静态 const 结构元素
- 在地图中搜索结构元素
- 在C++中传递结构数组 - 被调用函数中不存在结构元素,如何正确传递向量?
- 结构元素C 的枚举
- 将结构元素地址设置为C 中的null(单链接列表)
- OPENCV:为击中创建一个正方形结构元素
- 如何将结构元素传递给异步线程
- C - 基于另一个元素对结构元素进行排序
- 无法从传递到 pthread 的结构中访问结构元素
- 矢量的打印结构元素
- C结构元素对齐(ansi)
- 用3x3结构元素进行两次形态扩张,等于用6x6结构元素进行一次形态扩张
- 创建结构元素的动态数组,然后创建该结构的动态数组.C++
- 访问地图数据结构中的结构元素
- 尝试在文本文件中添加结构元素而不覆盖它