C Program to Print the Squares of Each Element of 2D Matrix

This page has a C Program to C Program to Print Squares of Each Element of 2D Matrix. It is clear that, this C program will display the Squares of Each Element of 2D array Matrix.For Example: If we give matrix elements using two dimensional array, the program will squares the each elements entered by us. The below given C program will Print Squares of Each Element of 2D Array Matrix. Kindly check out the program to Print Squares of Each Element of 2D Array Matrix.

Squares of Each Element of 2D Array Matrix Program

#include<stdio.h>

int main() {

int M[20][20];

int m, n, i, j;

printf("

Enter the Row and Column sizes of Matrix : ");

scanf("%d %d", &m, &n);

printf("



Enter the Matrix elements one by one

");

for (i = 1; i<=m; i++)

for (j = 1; j<=n; j++)

scanf("%d", &M[i][j]);

printf("

The Given Matrix is :



");

for (i = 1; i<=m; i++){

for (j = 1; j<=n; j++)

printf("\t %d", M[i][j]);

printf("



");

}

printf("

The Square of each elements of Matrix is :



");

for (i = 1; i<=m; i++){

for (j = 1; j<=n; j++)

printf("\t %d", (M[i][j] * M[i][j]));

printf("



");

}

return(0);

} Sample Output:

Enter the Row and Column sizes of Matrix : 3 4



Enter the Matrix elements one by one

0

1

2

3

4

5

6

7

8

9

10

11



The Given Matrix is :



0 1 2 3



4 5 6 7



8 9 10 11





The Square of each elements of Matrix is :



0 1 4 9



16 25 36 49



64 81 100 121

Related Popular Posts: