Ask a Teacher



write a c++ program to find the norm of a matrix?

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a[10][10],sum=0,i,j,m,n,trace=0;
float norm;
printf("enter order");
scanf("%d %d",&m,&n);
printf("enter elements ");
for(i=0;i<m;i++)
{for(j=0;j<m;j++)
scanf("%d",&a[i][j]);
}

for(i=0;i<m;i++)
{
for(j=0;j<m;j++)

{
sum=sum+(a[i][j]*a[i][j]);
if(i==j)
trace=trace+a[i][j];
}
}
norm=sqrt(sum);
printf("norm=%f\n trace=%d",norm,trace);
}


comments powered by Disqus