My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

there is a matrix N x N .Its elements consist of either value =1 or value=0. If there is a any zero in the row, then the output matrix should have all zeroes in that row. If there is a single zero in any column then that column should have all zeroes n the output matrix.

Wednesday, September 23, 2009

#include<iostream.h>
#include<conio.h>
void main()
{    clrscr();
    int mat[50][50],r,c,stack[500],id=0;
    for(int i=0;i<500;i++)
    stack[i]=-1;

    cout<<"enter the number of rows and columns resp: ";
    cin>>r>>c;
    cout<<"enter the elements: ";
    for(i=0;i<r;i++)
    {    for(int j=0;j<c;j++)
        {       cin>>mat[i][j];
        }
    }
    cout<<"ur entered matrix is: "<<endl;
    for(i=0;i<r;i++)
    {    for(int j=0;j<c;j++)
        {       cout<<mat[i][j]<<" ";
        }
        cout<<endl;
    }

    for(i=0;i<r;i++)
    {    for(int j=0;j<c;j++)
        {       if(mat[i][j]==0)
            {    stack[id]=i;
                id++;
                stack[id]=j;
                id++;
            }
        }
    }
    int k=0;

    while(stack[k]!=-1)
    {    for(i=0;i<r;i++)
        {    for(int j=0;j<c;j++)
            {    mat[(stack[k])][j]=0;
            }
            mat[i][(stack[k+1])]=0;
        }
        k+=2;
    }
    cout<<"after ur operation ur matrix become:\n";
    for(i=0;i<r;i++)
    {    for(int j=0;j<c;j++)
        {       cout<<mat[i][j]<<" ";
        }
        cout<<endl;
    }

    getch();
}

0 comments: