/* Programmed by David Isaacson, 2003
* Released into the Public Domain
*
* euclidiannorm.c
*
* This program will find the euclidian norm of a matrix A
*/
#include
#include
int main()
{
int i,j; //counters
int columns,rows; //columns and rows of A
double value; //value of A(i,j)
double sum=0; //sum of the squares
double norm; //just what it looks like
printf("This program will find the Euclidian Norm of a matrix you specify.\n");
printf("How many rows are in the matrix? ");
scanf("%i",&rows);
printf("How many columns? ");
scanf("%i",&columns);
//time to input A - we don't need to bother remembering the values, though
for(i=1;i<=rows;i++)
{
for(j=1;j<=columns;j++)
{
printf("What is the value at %i,%i? ",i,j);
scanf("%lf",&value);
sum+=value*value; //adding the square of the value
//to the total sum
}
}
//now we have the sum of all the squares
norm=sqrt(sum); //duh
printf("The euclidian norm of your matrix is: %lf\n",norm);
return 0;
}