You are on page 1of 1

// program in spiral order

#include <iostream>

using namespace std;

int main()
{
int i,j,a[10][10],m,n,row=0,col=0;
cout<<"enter the number of rows and column"<<endl;
cin>>m>>n;
cout<<"Enter the element:"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
// print the matrix in spinal order
cout<<"print the matrix :"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<endl;

}
while(row<m && col<n)
{
for(i=col;i<n;i++)
{
cout<<a[row][i]<<"\t";
}
row++;
for(i=row;i<m;i++)
{
cout<<a[i][n-1]<<"\t";
}
n--;
for(i=n-1;i>=col;i--)
{
cout<<a[m-1][i]<<"\t";
}
m--;
for(i=m-1;i>=row;i--)
{
cout<<a[m-1][col]<<"\t";
}
col++;

You might also like