Border elements of matrix!!!

Discussion in 'C' started by ophelia.2010, Dec 3, 2011.

  1. ophelia.2010

    ophelia.2010 New Member

    Joined:
    Oct 18, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    london
    I have the simplest logic for border elements !!! I will post it if anyone's interested !!!

    The simplest logic for BORDER/BOUNDARY ELEMENTS of a Matrix is here:

    #include<iostream.h>
    int A[10][10],i,j,m,n;
    cout<<"Enter the number of rows and columns\n";
    cin>>m>>n;
    for(i=0,i<m;i++)
    for(j=0;j<n;j++)
    cin>>A[j];
    for(i=0;i<m;i++)
    for(j=0;j<n;j++)
    if(((i==0)||(j==0))||((i==m-1)||(j==n-1)))
    cout<<A[j]<<"is a BORDER ELEMENT\n";
    }

    Instead of using 4 nested for loops ,you can use this logic -Just one nested for loop enclosing the single-line LOGIC!!!

    HOPE THIS WAS USEFUL!!!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice