Print a matrix | Elements given by user | C-Program

Write a program in c language to print a matrix, the elements of the matrix should be given by user ?



Tips:


          1.   print the word " Enter the element" to ask user for input.
          2.   Store the data in appropriate location.
          3.   Use nested for loop for taking the input.
          4.   Use it again to output it in a matrix form.
          5.   knowledge of loops and 2-d array required.


 

Code:

#include<stdio.h>

void main()

{
    int q,w;

    printf("enter no. of rows and column:");

    scanf("%d%d",&q,&w);

    int a[q][w],i,j;

    printf("Enter %d and %d number to form a matrix [row][column]\n",q,w);

    for(i=0;i<=q-1;i++)

      {  for(j=0;j<=w-1;j++)

           {  scanf("%d",&a[i][j]);  }
      }
    for(i=0;i<=q-1;i++)

      { for(j=0;j<=w-1;j++)

           { printf("%d\t",a[i][j]); }

        printf("\n");
      }

     getch();
}

Output:




----------------------------------------------------------------------------------------------------------------------------

          


Comments

Post a Comment

Give your feedback!
DO NOT SPAM !!
NO THIRD PARTY PROMOTIONAL LINK !!!! (else comment will be deleted.)

Popular posts from this blog

TOP 10 PROGRAMMING LANGAUAGES COMMING 2021 | ARTICLE

Write a C-program to swap two number:

Print Fibonacci Series using Recursion | C program :