WAP of C language to Print the Matrix of Fixed or Desired Order

Engg.... | 22:42 | | Best Blogger Tips
Matrix
Statement of C Program: This Program Reads and prints the elements of a Matrix:

#include<stdio.h>
#include<conio.h>
void main()
{
int matrix[9][9] ;                           /* Maximum Elements in the Matrix is 81 */
int matrix[3][3];                                      /* matrix of 9 elements */
int i, j;                                        /* 'i' used for rows and 'j' used for columns */
clrscr();

printf(" Enter the elements of Matrix\n");
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
scanf("%d" , &matrix[i][j] );
}
}                          /* Elements of Matrix Read (Input) with the help of scanf() Function */


printf(" Matrix is:\n");
for(i=0 ; i<3 ; i++)
{
for(j=0 ; j<3 ; j++)
{
printf("%d\t" , matrix[i][j] );                           /* '\t' used for Tab */
}                                                                    
printf("\n");                                          /* '\n' used for next line character */
}

getch();
}                                                                    /* End of main */


 Output:
 Enter the elements of Matrix
 9
 8
 7
 6
 5
 4
 3
 2
 1
 Matrix is:
 9   8   7
 6   5   4
 3   2   1


=> Note:  If you want to Print the Matrix of any Order then make few changes (Blue Colour) in the above Matrix. 

#include<stdio.h>
#include<conio.h>
void main()
{
int matrix[9][9];                                  /* Matrix of 81 Elements */
int i, j;
int Row , Column ;
clrscr();

printf(" Enter the order of Matrix\n");
scanf("%d%d" , &Row , &Column);

printf("Enter the elements of Matrix\n");
for(i=0 ; i<Row ; i++)
{
for(j=0 ; j<Column ; j++)
{
scanf("%d" , &matrix[i][j] );
}
}

printf(" Matrix is:\n");
for(i=0 ; i<Row ; i++)
{
for(j=0 ; j<Column ; j++)
{
printf("%d\t" , matrix[i][j] );
}
printf("\n");
}
getch();
}

 Output:
 Enter the order of Matrix
 3  3
 Enter the elements of Matrix
 9
 8
 7
 6
 5
 4
 3
 2
 1
 Matrix is:
 9   8   7
 6   5   4
 3   2   1

                                                                     That's All
Please Share it! :)
Do you like this Story?

Get Free Email Updates Daily!

Follow us!

2 comments:

  1. very good and easy example on printing matrix for beginners in c

    ReplyDelete

  2. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.


    python Training in Bangalore | python Training in Bangalore

    ReplyDelete