Skip to main content

C Program to input Values in a 2x2 square matrix and display the value

 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

Popular posts from this blog

C Program to Print first N Even Natural Number/in Reverse Order

  C Program to Print first N Even Natural Number.     In this example, we will find and print the first N even natural. Here we have used for loop to solve this program.      What are Natural Numbers? Natural Numbers are all positive numbers starting from 1 to infinity.      For Example:  1,2,3,4,5,6,.............................,n are all natural numbers. What are Even Numbers? Even numbers are those numbers whose remainder is 0 when divided by 2.     For Example: 2,4,6,8,10,.....,n are all even numbers.   PROGRAM: #include <stdio.h> #include <conio.h> void   main () {      int   i , x ;      printf ( "Enter the value of N : " );      scanf ( " %d " ,& x );      for ( i = 1 ; i <= x ; i ++)     {          printf ( " %d " , 2 * i );     }      getch (); } OUTPUT: C Program to Print First N Even Natural Number in Reverse Order. PROGRAM 123 #include <conio.h> #include <stdio.h> int   main () {      int   i , x ;      printf