Monday 10 September 2012

Array037

Input number in a matrix and find the high value by row of the Matrix.

#include <stdio.h>
#include <conio.h>

void main ( )
{
    int        n1[3][3], n2[3], i, j, h = 0;
    clrscr ( );

    printf ("\n\t\t\t Enter numbers in a matrix\n");
    printf("\n\t\t\t____________________________\n");
    for ( i = 0; i < 3; i++ )
    {          
                for ( j = 0; j < 3; j++)
                {          
                            printf("\n\t\t\t Position [%d] [%d]..:",i,j); scanf ("%d", &n1[i][j] );
                }
    }
    clrscr ( );

    printf("\n\n\n\n\t\t\t    Matrix\n\t\t\t______________\n\n\t\t\t");
    for ( i = 0; i < 3; i++ )
    {         
                for ( j = 0; j < 3; j++ )
                {          
                            printf ("%3d ", n1[i][ j] );
                }
                printf ("\n\t\t\t");
    }

    printf("\n\n\t\t Highest elements of the Matrix by row");
    printf("\n\t\t______________________________________");
    printf("\n\n\t\t\t\t");
    for ( i = 0; i < 3; i++ )
    {         
                h = 0;
                for ( j = 0; j < 3; j++ )
                {         
                            if ( n1[i][ j] > h )
                            {                   
                                       h = n1[i][ j];
                                       n2[i] = h;
                            }
                }
                printf ("\n\n\t\t Highest element of row no. [ %d ] = %d",i,n2[i]);;
    }
    getch ( );
}
Click here to contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...