Sunday 23 December 2012

Matrix creation by using only one dimensional array

/* compiler- Turbo c++ author- Mangilal Sharma --------------------------------------------------------*/
/* Do work of matrix by using only one dimensional array */
#include <conio.h>
#include <stdio.h>
#include <iostream.h>

void main()
{
 clrscr();
 int m,a[100],n;
 cout<<"Enter no. of rows for matrix:";
 cin>>n;
 cout<<"Enter no. of columns for matrix:";
 cin>>m;
 cout<<"Enter the elements for matrix:\n";
 int k=0;
 for(int i=0;i<n;i++)
 {
  for(int j=0;j<m;j++)
  {
   cout<<"Enter element for matrix location "<<i<<","<<j<<" :";
   cin>>a[k++];
  }
 }
 k=0;
 for(i=0;i<n;i++)
 {
  for(int j=0;j<m;j++)
  {
   cout<<"matrix location for"<<i<<","<<j<<" :";
   cout<<"is"<<&a[k++];cout<<endl;
  }
 }
 int row;
 printf("Which row we show u:");
 scanf("%d",&row);
 k=(row-1)*m;
 {
  for(int j=0;j<m;j++)
  {
   cout<<a[k++];cout<<"\t";
  }
  cout<<endl;
 }
 getch();
}
 /*=========================19Nov.,2011=============================*/

2 comments:

  1. .thank you for sharing useful post.
    wen programming tutorial
    welookups

    ReplyDelete

  2. nice article for beginners.thank you.
    javacodegeeks

    ReplyDelete

You are welcome, your comment helps me to make this blog more better.