Friday, 21 October 2016

2-D Array

C++ PROGRAMS


The following program takes the values for the elements of a 2-D Array and arranges and output is the arranged 2-D Array. Initially the program also asks the user to enter the number of rows and columns, so that it can arrange the elements accordingly.

Code:

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,r,c,A[10][10];
cout<<"Enter the number of Rows: ";
cin>>r;
cout<<"Enter the number of columns: ";
cin>>c;

for(i=0;i<r;i++)
{
 for(j=0;j<c;j++)
 {
  cin>>A[i][j];
 }
}

clrscr();
cout<<"Your Array is: \n";
for(i=0;i<r;i++)
{
 for(j=0;j<c;j++)
 {
  cout<<A[i][j]<<" ";
 }
 cout<<"\n";
}

getch();
}

Output:





For any suggestions or queries please comment !

No comments:

Post a Comment