WAP to find the norm of a matrix

Write a program to find the norm of a matrix

norm: square root of sum of square element of a matrix

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

int main() {
	float a[5][5],sum=0;
	int row,column,i,j;

	printf("Enter matrix size.\n");
	scanf("%d%d",&row,&column);

	printf("Enter elements in array:\n");
	for(i=0;i<row;i++){
		for(j=0;j<column;j++){
			printf("a[%d][%d]=",i,j);
			scanf("%f",&a[i][j]);
			sum+=a[i][j]*a[i][j];
		}
	}
	sum = sqrt(sum);
	printf("Result = %f",sum);

	return 0;
}

Output

Enter matrix size.
2
2
Enter elements in array:
a[0][0]=1
a[0][1]=2
a[1][0]=3
a[1][1]=4
Result = 5.477226

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments