Array is a type of structured data that is useful to store large amounts of data are the same type. Parts that make up the array called array elements, each element can be accessed separately through the array index. whereas Is a variable that stores a set of data that has the same type and elements that will be accessed only through an index or subscript. below I present one-dimensional arrays into two-dimensional array..
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int n, baris, kolom;
int data[20];
int output[40][40];
int e=0;
cout<<"PROGRAM CHANGE DIMENSIONS TO ARRAY 1 ARRAY 2 DIMENSIONS";
cout<<endl;
cout<<"Masukan banyaknya bilangan :";
cin>>n;
for (int i=0; i<n;i++)//the process of entering numbers
{
cout<<"data ke-"<<i<<" = ";
cin>>data[i];
}
for (int j=0; j<n;j++)//the process of displaying an array of one-dimensional
{
cout<<data[j];
}
cout<<endl<<"\n";
cout<<"masukan banyaknya kolom: ";
cin>>kolom;
cout<<"masukan banyaknya baris: ";
cin>>baris;
for (int i=0;i<baris;i++)//change process into two-dimensional array of one-dimensional
{
for (int j=0;j<kolom;j++)
{
output[i][j]=data[e];
e++;
}
}
for (int i=0;i<baris;i++) //the process of displaying a two dimensional array
{
for (int j=0;j<kolom;j++)
{
cout<<output[i][j]<<" ";
}
cout<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
Tidak ada komentar:
Posting Komentar