怎么创建一个二维数组(n行2列)来一 一存储本程序中的x和y的值,有劳各位能最好写下程序
#include<iostream>
using namespace std;
double y;
int main()
{
for (int x = 0; x < 9; x++)
{
y = x + 1;
cout << "y的数值为: " << y << endl;
}
system("pause");
return 0;
}
#include<iostream>
using namespace std;
double y;
int a[9][2];
int main()
{
for (int x = 0; x < 9; x++)
{
y = x + 1;
a[x][0] = x;
a[x][1] = y;
cout << "y的数值为: " << y << endl;
}
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 2; j++)
cout << " " << a[i][j];
cout << endl;
}
system("pause");
return 0;
}
代码如下:
#include<iostream>
using namespace std;
int main()
{
double y=0;
int n=0;
cout<<"输入行数n:";
cin>>n;
double** p = new double* [n];
for(int i=0; i <n; i++)
p[i] = new double[2];
for(int i=0; i<n; i++)
{
for(int j=0; j<2; j++)
{
y++;
p[i][j]=y;
}
}
cout<<"数组数据如下:"<<endl;
for(int i=0; i<n; i++)
{
for(int j=0; j<2; j++)
{
cout<<p[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
有帮助望采纳,谢谢!