Write a program to find the norm of a matrix.

/* Norm is the sum of the squars of all the elements of the matrix. */

#include<stdio.h>
#include<math.h>
main()
{ int i,j,n,m,a[10][10],sum=0;
double norm;
printf("\nEnter the dimensions:: ");
scanf("%d%d",&n,&m);

printf("\nEnter the eleents of matrix::\n");
for(i=0;i<n;i++)
for(j=0;j<m;j++)
scanf("%d",&a[i][j]);

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

for(i=0;i<n;i++)
for(j=0;j<m;j++)
{ sum+=(a[i][j] * a[i][j]);
}

norm=sqrt((double)sum);

printf("\nNORM:: %lf", norm);
}
Advertisements

2 thoughts on “Write a program to find the norm of a matrix.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s