u

Saturday, 2 June 2012

C++ Program for :Matrices:To implement cell value of a defined matrix

C++ Program for :Matrices:To implement cell value of a defined matrix.
Input: Row & Col. and Output : Cell element of the points Row, Col.

#include <stdlib.h>
#include <iostream.h>
#include<conio.h>
int main()
{
clrscr();
  int x, y;                    // Loop Counter
  int x1, y1, repeat;
  //         x, y           Think like that if you input x = 1, y = 3
  //                        You will output "69", that how a matrix works
  int matrix[4][4] = { 12, 4, 23, 6,
               45, 78, 3, 57,
               69, 23, 9, 2,
               34, 11, 5, 99 };
  cout<<"My Matrix: "<< endl << endl;
  for( x = 0; x < 4; x++)
  {
       for( y = 0; y < 4; y++)
       {
        cout<< matrix[x][y] << " ";
       }
       cout<<endl;
  }
  cout<< endl <<"Both x and y have a max point of 3" << endl;
  do
  {
       cout<< endl <<"Enter in x and y points[ x <space> y ]: ";
       cin>> x1 >> y1;

       cout<<"Point ("<< x1 <<", " << y1 <<") = " << matrix[x1][y1] << endl
       << endl;
       cout<<"Would You like Output new points (0 to quit)? ";
       cin>> repeat;
  }while( repeat != 0);
  cout<<endl;
  cout<<"Press any key to continue";
  getch();
  return 0;
}

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More