Tuesday 19 February 2013

Ragged matrix

ragged matrix is that which has unequal number of elements in the each row
#include<iostream>
using namespace std;
#include<conio.h>
int main()
{int r,j,i,pos[]={2,1,3,5,7,4,6,9,10,8,11,13,12,15,14};
cout<<"enter how many rows u want to display of a ragged matrix";
cin>>r;int a[r][15];
cout<<"Enter the elements\n";
int s=1,n;
for(i=0;i<r;i++)
  { for(j=0;j<pos[i];j++)
      cin>>a[i][j];
  }
cout<<"\n\n\n\n";
for(i=0;i<r;i++)
  { for(j=0;j<pos[i];j++)
    cout<<a[i][j]<<"  ";
   cout<<endl;
  }
       getch();
}

No comments:

Post a Comment