Monday, September 12, 2011

print the given matrix

print the given matrix

#include<stdio.h>
#include<conio.h>
main()
{

    int a[5][5],m,n,i,j;
    clrscr();
    printf("\n enter the no. of rows of the matrix:");
    scanf("%d",&m);
    printf("\n enter the no. of columns of the matrix:");
    scanf("%d",&n);
    for(i=0;i<m;i++)  /* scan the entire matrix  */
        for(j=0;j<n;j++)
        {
        printf("\n enter the  a[%d][%d]  element:",i+1,j+1);
        scanf("%d",&a[i][j]);
        }
    if(m==n)  /* check whether square matrix or not  */
        printf("\n The given matrix is a square matrix and ");
    else
        printf("\n The given matrix is not a square matrix and ");
    printf("\n The elements of the given matrix are:");
    for(i=0;i<m;i++)  /* print the matrix  */
    {
    printf("\n");
        for(j=0;j<n;j++)
        printf("\t %d",a[i][j]);
    }
    getch();
}

No comments:

Post a Comment

Popular 5 Posts Last 7 days