Thursday 27 February 2014

C++ MATRIX ADD SUBTRACT MULTIPLY DIVIDE OPERATION AND FIND MAXIMUM MINIMUM VALUE IN MATRIX

//CODE

// we make 3 X 4 matrix

/***********************************************************************************/
#include<iostream>
#include<stdlib.h>
#include<cmath>

using namespace std;

void main()
{
    int Matris[3][4];
    int j=0;
    int max_col,max_row,min_col,min_row;
    /**************insert in matrics**************************/
    int i=0;
    while(i<3)//rows<#
    {

        while(j<4)
        {
        cout<<"enter the value of the row and colomn: ["<<i<<"]["<<j<<"]"<<endl;
        cin>>Matris[i][j];
        j++;
        }
        j=0;
        i++;
    }
        /*************************COPY RIGHTS TO PROGRAMMINGISBEST/{UMARJAVED01@GMAIL.COM}*********************************************************/


    /************Showing values in matrices********************/

    cout<<endl<<"----------Values Are in Matrices as under----------"<<endl<<endl;
    for(int m=0;m<3;m++)
    {
        for(int f=0;f<4;f++)
        {
            if(f==0)
            {
            //    cout<<"Value Stored in row and colomn of Matric ["<<m<<"]["<<f<<"]"<<" IS : "<<Matris[m][f]<<endl;
            cout<<Matris[m][f];
            }
            if(f!=0 && f!=3)
            {
            cout<<"\t"<<Matris[m][f];
            }
            if(f==3)
            {
            cout<<"\t"<<Matris[m][f]<<endl;
            }
        }
    }


    /************Decleration of new datatype to find maximum and minimum********************/

    int max,min;
    max = min = Matris[0][0];

    cout<<endl<<"\n----------Finding maximum and minimum values----------"<<endl<<endl;
   
   
    //less check
        /*************************COPY RIGHTS TO PROGRAMMINGISBEST/{UMARJAVED01@GMAIL.COM}*********************************************************/

    for(int p=0;p<3;p++){
        for(int l=0;l<4;l++){
    {
        if(min>Matris[p][l])
        {
            min = Matris[p][l];
            min_col = p;
            min_row = l;
        }
        if(max<Matris[p][l])
        {
            max = Matris[p][l];
            max_col = p;
            max_row = l;
        }}
        }
    }


    cout<<"Maximum value found in matrices is : "<<Matris[max_col][max_row]<<endl;
    cout<<"Minimum value found in matrices is : "<<Matris[min_col][min_row]<<endl;

    /************************SECOND MATRICS*************************************************/
    int Matris2[3][4];
    i=0,j=0;
    while(i<3)//rows<#
    {

        while(j<4)
        {
        cout<<"enter the value of the row and colomn: ["<<i<<"]["<<j<<"]"<<endl;
        cin>>Matris2[i][j];
        j++;
        }
        j=0;
        i++;
    }
        /*************************COPY RIGHTS TO PROGRAMMINGISBEST/{UMARJAVED01@GMAIL.COM}*********************************************************/

    cout<<endl<<"----------Values Are in Matrices # 2 as under----------"<<endl<<endl;
    for(int m=0;m<3;m++)
    {
        for(int f=0;f<4;f++)
        {
            if(f==0)
            {
            cout<<Matris2[m][f];
            }
            if(f!=0 && f!=3)
            {
            cout<<"\t"<<Matris2[m][f];
            }
            if(f==3)
            {
            cout<<"\t"<<Matris2[m][f]<<endl;
            }
        }
    }

    max = min = Matris2[0][0];

   
    for(int p=0;p<3;p++){
        for(int l=0;l<4;l++){
    {
        if(min>Matris2[p][l])
        {
            min = Matris2[p][l];
            min_col = p;
            min_row = l;
        }
        if(max<Matris2[p][l])
        {
            max = Matris[p][l];
            max_col = p;
            max_row = l;
        }}
        }
    }
    cout<<"Maximum value found in matrices is : "<<Matris2[max_col][max_row]<<endl;
    cout<<"Minimum value found in matrices is : "<<Matris2[min_col][min_row]<<endl;

    /************************SUM OF MATRICS****************************************************/

    int sumMatrics[3][4];
    for(int z=0;z<3;z++)
    {
        for(int x=0;x<4;x++)
        {
            sumMatrics[z][x] = Matris[z][x] + Matris2[z][x];
        }
    }
        /*************************COPY RIGHTS TO PROGRAMMINGISBEST/{UMARJAVED01@GMAIL.COM}*********************************************************/

   
    cout<<endl<<"----------Values Are in SUM MATRICS as under----------"<<endl<<endl;
    for(int m=0;m<3;m++)
    {
        for(int f=0;f<4;f++)
        {
            if(f==0)
            {
                cout<<sumMatrics[m][f];
            }
            if(f!=0 && f!=3)
            {
                cout<<"\t"<<sumMatrics[m][f];
            }
            if(f==3)
            {
                cout<<"\t"<<sumMatrics[m][f]<<endl;
            }
        }
    }

    max = min =  sumMatrics[0][0];
        /*************************COPY RIGHTS TO PROGRAMMINGISBEST/{UMARJAVED01@GMAIL.COM}*********************************************************/

   
    for(int p=0;p<3;p++)
    {
        for(int l=0;l<4;l++)
        {
            {
                if(min>sumMatrics[p][l])
                {
                    min = sumMatrics[p][l];
                    min_col = p;
                    min_row = l;
                }
                if(max<sumMatrics[p][l])
                {
                    max = sumMatrics[p][l];
                    max_col = p;
                    max_row = l;
                }
            }
        }
    }
    cout<<"Maximum value found in matrices is : "<<sumMatrics[max_col][max_row]<<endl;
    cout<<"Minimum value found in matrices is : "<<sumMatrics[min_col][min_row]<<endl;

    /************************SUBTRACTION OF MATRICS****************************************************/

    int subMatrics[3][4];
    for(int z=0;z<3;z++)
    {
        for(int x=0;x<4;x++)
        {
            if( Matris2[z][x]>Matris[z][x]){
                subMatrics[z][x] =  Matris2[z][x] - Matris[z][x];}
            else
            {subMatrics[z][x] = Matris[z][x]-Matris2[z][x] ;}
        }
    }
        /*************************COPY RIGHTS TO PROGRAMMINGISBEST/{UMARJAVED01@GMAIL.COM}*********************************************************/

   
    cout<<endl<<"----------Values Are in SUM MATRICS as under----------"<<endl<<endl;
    for(int m=0;m<3;m++)
    {
        for(int f=0;f<4;f++)
        {
            if(f==0)
            {
                cout<<subMatrics[m][f];
            }
            if(f!=0 && f!=3)
            {
                cout<<"\t"<<subMatrics[m][f];
            }
            if(f==3)
            {
                cout<<"\t"<<subMatrics[m][f]<<endl;
            }
        }
    }
        /*************************COPY RIGHTS TO PROGRAMMINGISBEST/{UMARJAVED01@GMAIL.COM}*********************************************************/

    max = min =  subMatrics[0][0];

   
    for(int p=0;p<3;p++){
        for(int l=0;l<4;l++){
    {
        if(min>subMatrics[p][l])
        {
            min = subMatrics[p][l];
            min_col = p;
            min_row = l;
        }
        if(max<subMatrics[p][l])
        {
            max = subMatrics[p][l];
            max_col = p;
            max_row = l;
        }}
        }
    }
    cout<<"Maximum value found in matrices is : "<<subMatrics[max_col][max_row]<<endl;
    cout<<"Minimum value found in matrices is : "<<subMatrics[min_col][min_row]<<endl;

    /************************Multiplication OF MATRICS****************************************************/

    int multMatrics[3][4];
    for(int z=0;z<3;z++)
    {
        for(int x=0;x<4;x++)
        {
            multMatrics[z][x] =  Matris2[z][x] * Matris[z][x];
        }
    }
        /*************************COPY RIGHTS TO PROGRAMMINGISBEST/{UMARJAVED01@GMAIL.COM}*********************************************************/

   
    cout<<endl<<"----------Values Are in MULTIPLY MATRICS as under----------"<<endl<<endl;
    for(int m=0;m<3;m++)
    {
        for(int f=0;f<4;f++)
        {
            if(f==0)
            {
                cout<<multMatrics[m][f];
            }
            if(f!=0 && f!=3)
            {
                cout<<"\t"<<multMatrics[m][f];
            }
            if(f==3)
            {
                cout<<"\t"<<multMatrics[m][f]<<endl;
            }
        }
    }

    max = min =  multMatrics[0][0];

        /*************************COPY RIGHTS TO PROGRAMMINGISBEST/{UMARJAVED01@GMAIL.COM}*********************************************************/

    for(int p=0;p<3;p++){
        for(int l=0;l<4;l++){
    {
        if(min>multMatrics[p][l])
        {
            min = multMatrics[p][l];
            min_col = p;
            min_row = l;
        }
        if(max<multMatrics[p][l])
        {
            max = multMatrics[p][l];
            max_col = p;
            max_row = l;
        }}
        }
    }
    cout<<"Maximum value found in matrices is : "<<multMatrics[max_col][max_row]<<endl;
    cout<<"Minimum value found in matrices is : "<<multMatrics[min_col][min_row]<<endl;

    /************************DIVISION OF MATRICS****************************************************/

    int divMatrics[3][4];
    for(int z=0;z<3;z++)
    {
        for(int x=0;x<4;x++)
        {
            divMatrics[z][x] =  Matris2[z][x] / Matris[z][x];
        }
    }
        /*************************COPY RIGHTS TO PROGRAMMINGISBEST/{UMARJAVED01@GMAIL.COM}*********************************************************/

   
    cout<<endl<<"----------Values Are in DIVISION MATRICS as under----------"<<endl<<endl;
    for(int m=0;m<3;m++)
    {
        for(int f=0;f<4;f++)
        {
            if(f==0)
            {
                cout<<divMatrics[m][f];
            }
            if(f!=0 && f!=3)
            {
                cout<<"\t"<<divMatrics[m][f];
            }
            if(f==3)
            {
                cout<<"\t"<<divMatrics[m][f]<<endl;
            }
        }
    }
        /*************************COPY RIGHTS TO PROGRAMMINGISBEST/{UMARJAVED01@GMAIL.COM}*********************************************************/

    max = min =  divMatrics[0][0];

   
    for(int p=0;p<3;p++){
        for(int l=0;l<4;l++){
    {
        if(min>divMatrics[p][l])
        {
            min = divMatrics[p][l];
            min_col = p;
            min_row = l;
        }
        if(max<divMatrics[p][l])
        {
            max = divMatrics[p][l];
            max_col = p;
            max_row = l;
        }}
        }
    }
    cout<<"Maximum value found in matrices is : "<<divMatrics[max_col][max_row]<<endl;
    cout<<"Minimum value found in matrices is : "<<divMatrics[min_col][min_row]<<endl;


   
    cout<<"\n\n\t\t\t PRogRam PRO C++ (UMAR JAVED)"<<endl;
    cout<<"\n\n\n\t\t\t***************************"<<endl;
    /*************************COPY RIGHTS TO PROGRAMMINGISBEST/{UMARJAVED01@GMAIL.COM}*********************************************************/
    int h;
    cin>>h;
}


/**************************output**********************************/

//enter the value of the row and colomn: [0][0]
//5
//enter the value of the row and colomn: [0][1]
//1
//enter the value of the row and colomn: [0][2]
//2
//enter the value of the row and colomn: [0][3]
//6
//enter the value of the row and colomn: [1][0]
//11
//enter the value of the row and colomn: [1][1]
//7
//enter the value of the row and colomn: [1][2]
//2
//enter the value of the row and colomn: [1][3]
//6
//enter the value of the row and colomn: [2][0]
//4
//enter the value of the row and colomn: [2][1]
//3
//enter the value of the row and colomn: [2][2]
//8
//enter the value of the row and colomn: [2][3]
//9
//
//----------Values Are in Matrices as under----------
//
//5       1       2       6
//11      7       2       6
//4       3       8       9
//
//
//----------Finding maximum and minimum values----------
//
//Maximum value found in matrices is : 11
//Minimum value found in matrices is : 1
//enter the value of the row and colomn: [0][0]
//11
//enter the value of the row and colomn: [0][1]
//52
//enter the value of the row and colomn: [0][2]
//65
//enter the value of the row and colomn: [0][3]
//75
//enter the value of the row and colomn: [1][0]
//32
//enter the value of the row and colomn: [1][1]
//21
//enter the value of the row and colomn: [1][2]
//25
//enter the value of the row and colomn: [1][3]
//85
//enter the value of the row and colomn: [2][0]
//75
//enter the value of the row and colomn: [2][1]
//65
//enter the value of the row and colomn: [2][2]
//12
//enter the value of the row and colomn: [2][3]
//32
//
//----------Values Are in Matrices # 2 as under----------
//
//11      52      65      75
//32      21      25      85
//75      65      12      32
//Maximum value found in matrices is : 32
//Minimum value found in matrices is : 52
//
//----------Values Are in SUM MATRICS as under----------
//
//16      53      67      81
//43      28      27      91
//79      68      20      41
//Maximum value found in matrices is : 91
//Minimum value found in matrices is : 53
//
//----------Values Are in SUM MATRICS as under----------
//
//6       51      63      69
//21      14      23      79
//71      62      4       23
//Maximum value found in matrices is : 79
//Minimum value found in matrices is : 4
//
//----------Values Are in MULTIPLY MATRICS as under----------
//
//55      52      130     450
//352     147     50      510
//300     195     96      288
//Maximum value found in matrices is : 510
//Minimum value found in matrices is : 50
//
//----------Values Are in DIVISION MATRICS as under----------
//
//2       52      32      12
//2       3       12      14
//18      21      1       3
//Maximum value found in matrices is : 52
//Minimum value found in matrices is : 1