Dynamic Memory Allocations in 2D Array with Linear Search 

Input: 

Array Row[] Column[] 

Output :

Position Of A Value 

 

Code:  

 #include<iostream>
using namespace std;

int main()
{
    int i,j,n,row , col,s,t=0;

    int **matrix;

    cout<<"Enter The Number Of Row : ";
    cin>>row;
    cout<<"Enter The Number Of Coloum : ";
    cin>>col;
    matrix= new int *[row];
    for(i=0;i<row;i++)
    {
        matrix[i]= new int [col];
    }
    cout<<endl<<"Enter The Number of Elements :";
    for(i=0;i<row;i++)
    {

        for(j=0;j<col;j++)
        {
            cout<<endl<<"Row["<<i+1<<"]"<<"Col["<<j+1<<"]=";
            cin>>matrix[i][j];
        }
    }
    cout<<"Enter The Number To Search : ";
    cin>>s;

    for(i=0;i<row;i++)
    {

        for(j=0;j<col;j++)
        {
           if(matrix[i][j]==s)
           {
               cout<<"\n\n\t\tNumber Found And The Position = "<<"\tRow["<<i+1<<"]"<<"\t\tColoum ["<<j+1<<"]";
               t=1;
           }
        }
    }
    if(t==0)
    {
        cout<<"\n\n\t Not Found";

    }
    return 0;

}

Output


 

Comments

Popular posts from this blog