#include <stdio.h>
#include <math.h>
#include <stdlib.h>
double Norm_1(int n, double x[]);
double Norm_2(int n, double x[]);
double Norm_inf(int n, double x[]);
int main(){
int n;
double x[100];
scanf("%d", &n);
for(int i = 0; i < n; i++){
scanf("%lf", &x[i]);
}
printf("%lf %lf %lf", Norm_1(n, x), Norm_2(n, x), Norm_inf(n, x));
return 0;
}
double Norm_1(int n, double x[]){
double norm_1;
//计算向量x的1-范数
for (int i=0; i<n; i++) {
norm_1 += fabs(x[i]);
}
return norm_1;
}
double Norm_2(int n, double x[]){
double norm_2;
//计算向量x的2-范数
for (int i=0; i<n; i++) {
norm_2 += pow(x[i], 2);
}
norm_2 = sqrt(norm_2);
return norm_2;
}
double Norm_inf(int n, double x[]){
double norm_inf = fabs(x[0]);
//计算向量x的无穷范数
for (int i=1; i<n; i++) {
if (fabs(x[i]) > norm_inf) {
norm_inf = fabs(x[i]);
}
}
return norm_inf;
}
06-04
2万+
11-03
1万+