C Program to input Values in a 2x2 square matrix and display the value
In this example, we will accept values from the user in a 2x2 square and matrix and then it is displayed. To solve this problem we must know what is matrices and arrays.
What are Arrays?
An array is a data structure for storing more than one data member of similar data type.
Array can be of following types:
- One-dimensional Array
- Two-dimensional Array
- Multi-dimensional Array
In Array we must always initialize values.
PROGRAM
#include<stdio.h>
#include<conio.h>
int main()
{
int a[2][2],i,j;
printf("Enter the values of the matrix:");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Displaying the Matrix.\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
return 0;
}
OUTPUT
Enter the values of the matrix:48
65
23
34
Displaying the Matrix.
48 65
23 34
NOTE: You Can Comment Your Code if you have solved differently and we will pin it in the comment section. Let's Learn together.
MOTTO:
You Learn, I Learn together We Learn.
Comments
Post a Comment
Please do not spam any link