Create matrix and print C program

It’s a create matrix and print C program that inputs numbers from the user and stores these numbers in two-dimensional arrays as to create a matrix and then print matrix on the screen.

To understand this program, it’s better you should know the following topics:

Program (1): to create and print matrix.

#include<stdio.h>
#include<conio.h>
void main()
{
//consider matrix A size as 3x2
int a[2][2],i,j;
//accepting values into an array a
printf("Accept elements in Matrix A\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
scanf("%d",&a[i][j]);
}
//to print array A elements
printf("\nThe matrix A is\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%6d",a[i][j]);
}
printf("\n");
}
getch();
}

Output (1)

Accept elements in Matrix A
1
2
3
4

The matrix A is
     1     2
     3     4

Published by

Electrical Workbook

We provide tutoring in Electrical Engineering.

Leave a Reply

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