I'm a little confused as to how I would write the end of the if statement for infinityNorm. This is a Euclidean norm program. For example, the Euclidean norm of {6.7, 9.2, 4.3, 6.1} is the square root of (6.72+9.22+4.32+6.12
} = 13.6099. Wouldn't I return the value of the largest integer?
#include <iostream>
#include <iomanip>
usingnamespace std;
double euclideanNorm(double v[], int sz);
double infinityNorm(double v[], int sz);
int main() {
constint N = 4;
double data[N] = {6.7, 9.2, 4.3, 6.1} ;
cout << "The Euclidean norm is " << fixed << setprecision(4) <<
euclideanNorm(data,N) << endl;
//cout << "The Infinity norm is " << fixed << setprecision(4) <<
// infinityNorm(data,N) << endl;
return 0;
}
double euclideanNorm(double v[], int sz){
int i;
double sum = 0;
for (i = 0; i < sz; i++)
sum += v[i]*v[i];
return sqrt(sum);
}
double infinityNorm(double v[], int sz){
int i;
double largest = abs(v[0]);
for (i = 1; i < sz; i++)
if (abs(v[i]) > largest);
// THIS LINE
return largest;
}