Tuesday, January 11, 2011

CPP-Function array 2 dimentions

Code :
**********************************************
//Function of Array 2 dimention
#include<iostream>
#define Max 20
using namespace std;
int main()
{   int A[Max][Max],B[Max][Max],rowa,columna,C[Max][Max],rowb,columnb;
    void InputData(int(*)[Max],int*,int*,char);//...(int[Max][Max]...
    void DisplayData(int(*)[Max],int,int,char);
    InputData(A,&rowa,&columna,'A');
    DisplayData(A,rowa,columna,'A');
    InputData(B,&rowb,&columnb,'B');
    DisplayData(B,rowb,columnb,'B');
    return 0;
}
void InputData(int x[Max][Max],int*R,int*C,char ch)
{   int row,column,i,j;
    cout<<"\nInput Matrix : "<<ch<<endl;
    cout<<"input Row and Column\n";
    cin>>row>>column;
    for(i=0;i<row;i++)
    {    for(j=0;j<column;j++)
            {   cout<<i+1<<","<<j+1<<" : ";
                cin>>x[i][j];
            }
    }
    *R=row,*C=column;
}
void DisplayData(int Z[Max][Max],int R,int C,char M)
{   int j,i;
    cout<<"\nOutput Matrix : "<<M<<endl;
    for(i=0;i<R;i++)
    {   for(j=0;j<C;j++)
        {   cout<<Z[i][j]<<" ";}
        cout<<endl;
    }

}
**********************************************
Output:
**********************************************
Input Matrix : A
input Row and Column :


Input Matrix : B
input Row and Column :

Output Matrix : B

**********************************************

No comments:

Post a Comment