C Program to Find the Normal of a Matrix

Write a C program to find the normal of a matrix using for loop. In this C matrix normal example, we use nested for loop to iterate and find the matrix square. Next, the Mathematical sqrt function will find the matrix square root. Thus, the normal of a matrix is the square root of the sum of the matrix items squares.

#include <stdio.h>
#include <math.h>

int main()
{
	int i, j, rows, columns, normal = 0;

	printf("Enter Normal Matrix Rows and Columns =  ");
	scanf("%d %d", &rows, &columns);

	int Norm_arr[rows][columns];

	printf("Please Enter the Normal Matrix Items =  \n");
	for (i = 0; i < rows; i++)
	{
		for (j = 0; j < columns; j++)
		{
			scanf("%d", &Norm_arr[i][j]);
		}
	}

	for (i = 0; i < rows; i++)
	{
		for (j = 0; j < columns; j++)
		{
			normal = normal + (Norm_arr[i][j]) * (Norm_arr[i][j]);
		}
	}
	float actNormal = sqrt(normal);
	printf("\nThe Square Of the Matrix = %d", normal);
	printf("\nThe Normal Of the Matrix = %.2f\n", actNormal);
}
C Program to Find the Normal of a Matrix

C program to find the normal of a matrix using a while loop.

#include <stdio.h>
#include <math.h>

int main()
{
	int i, j, rows, columns, normal = 0;

	printf("Enter Normal Matrix Rows and Columns =  ");
	scanf("%d %d", &rows, &columns);

	int Norm_arr[rows][columns];

	printf("Please Enter the Normal Matrix Items =  \n");
	i = 0;
	while (i < rows)
	{
		j = 0;
		while (j < columns)
		{
			scanf("%d", &Norm_arr[i][j]);
			normal = normal + (Norm_arr[i][j]) * (Norm_arr[i][j]);
			j++;
		}
		i++;
	}

	float actNormal = sqrt(normal);
	printf("\nThe Square Of the Matrix = %d", normal);
	printf("\nThe Normal Of the Matrix = %.2f\n", actNormal);
}
Enter Normal Matrix Rows and Columns =  3 3
Please Enter the Normal Matrix Items =  
10 20 30
40 50 60
70 80 90

The Square Of the Matrix = 28500
The Normal Of the Matrix = 168.82

This C program calculates the normal of a given matrix using the do while loop.

#include <stdio.h>
#include <math.h>

int main()
{
	int i, j, rows, columns, normal = 0;

	printf("Enter Normal Matrix Rows and Columns =  ");
	scanf("%d %d", &rows, &columns);

	int Norm_arr[rows][columns];

	printf("Please Enter the Normal Matrix Items =  \n");
	i = 0;

	do
	{
		j = 0;
		do
		{
			scanf("%d", &Norm_arr[i][j]);
			normal = normal + (Norm_arr[i][j]) * (Norm_arr[i][j]);

		} while (++j < columns);

	} while (++i < rows);

	float actNormal = sqrt(normal);
	printf("\nThe Square Of the Matrix = %d", normal);
	printf("\nThe Normal Of the Matrix = %.2f\n", actNormal);
}
Enter Normal Matrix Rows and Columns =  4 4
Please Enter the Normal Matrix Items =  
10 20 30 40
50 60 70 80
90 10 25 35
45 55 65 75

The Square Of the Matrix = 45350
The Normal Of the Matrix = 212.96