C Program Matrix Input Output

By | March 15, 2020

C Program Matrix Input Output

C Program Matrix Input Output

C Program Matrix Input Output

/* Write a C program to input a m x n matrix
   and displaying in matrix format 
     www.easycodebook.com
*/ 
#include <stdio.h>
 
 
int main()
{
    int matrix[10][10];
    int i,j,m,n;
     
    printf("Enter number of Rows [10 Maximum]:");
    scanf("%d",&m);
    printf("Enter number of Columns [10 Maximum:]:");
    scanf("%d",&n);
 
    printf("\nEnter %d matrix elements in %d x %d Matrix:\n",m*n,m,n);
    for(i=0;i< m;i++)
    {
        for(j=0;j< n;j++)
        {
            printf("Enter element in Matrix[%d,%d]: ",i,j);
            scanf("%d",&matrix[i][j]);
        }
    }
 
    printf("\nYou have entered the Matrix  :\n");
    for(i=0;i< m;i++)
    {
        for(j=0;j< n;j++)
        {
            printf("%d\t",matrix[i][j]);/*print an element and a tab space*/
        }
        printf("\n");   /*for new line after completion of one row*/
    }
    return 0;   
}
Output

Enter number of Rows [10 Maximum]:3
Enter number of Columns [10 Maximum:]:3

Enter 9 matrix elements in 3 x 3 Matrix:
Enter element in Matrix[0,0]: 1
Enter element in Matrix[0,1]: 2
Enter element in Matrix[0,2]: 3
Enter element in Matrix[1,0]: 4
Enter element in Matrix[1,1]: 5
Enter element in Matrix[1,2]: 6
Enter element in Matrix[2,0]: 7
Enter element in Matrix[2,1]: 8
Enter element in Matrix[2,2]: 9

You have entered the Matrix  :
1       2       3
4       5       6
7       8       9

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *