20/02/2019

Print a MATRIX in C-Programming using array

Print a MATRIX in C-Programming using array: 

Here we print a matrix with the help of array; so what is a matrix? - Matrix is a collection of numbers arranged into a fixed number of rows and columns. The numbers can be real or complex, but we use real numbers here.
Print a MATRIX in C-Programming using array

Code:

Print a MATRIX in C-Programming using array

#include<stdio.h>
#include<conio.h>
int main()
{
  int m,n,a[100][100],i,j;
  printf("Enter the order of the matrix:\n");
  scanf("%d%d",&m,&n);
  printf("Give the %d*%d matrix",m,n);
  printf("\n");
  for(i=0;i<n;i++)
  {
    printf("Enter the %d row\n",i+1);
    for(j=0;j<m;j++)
    scanf("%d",&a[i][j]);
  }
  printf("The given matrix is:\n");
  for (i=0;i<n;i++)
  {
    for(j=0;j<m;j++)
    printf("%d\t",a[i][j]);
    printf("\n");
  }
}

Output: 

The output is given below-
Print a MATRIX in C-Programming using array

Explanation: 

1. First we use header package <stdio.h> and <conio.h>. To know more visit package page.
2. We use 5 integer variables. we use m and n for taking the order of the matrix. Then we use a[100][100] variable which called array its means that a variable has 100x100 box space, easily you can think that it would give a 10000 box space. You can change the array size 100 by changing it with any number. We use i and j variable for the use of for-loop.
3. First we take the order of the matrix by users and store it in m and n.
4. After that we store the numbers in variable a[100][100] with the help of for-loop. we scan the numbers and store all the numbers in a[100][100] variable. Now we have to print all the numbers that we stored it in the variable a[100][100], for that we use for-loop again for to print those numbers.

If you have any doubts then comment below.

No comments:

Post a Comment