#include <stdio.h>
#include <math.h>
int main() {
int n, i, j;
int trace = 0;
double norm = 0.0;
printf("Enter the size of the square matrix: ");
int matrix[n][n];
printf("Enter the elements of the matrix:\n"); for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &matrix
[i
][j
]); }
}
// Calculate trace and norm
for (i = 0; i < n; i++) {
trace += matrix[i][i]; // sum of principal diagonal elements
for (j = 0; j < n; j++) {
norm += matrix[i][j] * matrix[i][j]; // sum of squares of elements
}
}
norm
= sqrt(norm
); // Square root of sum of squares
printf("Trace of the matrix: %d\n", trace
); printf("Norm of the matrix: %.2f\n", norm
);
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxtYXRoLmg+CgppbnQgbWFpbigpIHsKICAgIGludCBuLCBpLCBqOwogICAgaW50IHRyYWNlID0gMDsKICAgIGRvdWJsZSBub3JtID0gMC4wOwoKICAgIHByaW50ZigiRW50ZXIgdGhlIHNpemUgb2YgdGhlIHNxdWFyZSBtYXRyaXg6ICIpOwogICAgc2NhbmYoIiVkIiwgJm4pOwoKICAgIGludCBtYXRyaXhbbl1bbl07CgogICAgcHJpbnRmKCJFbnRlciB0aGUgZWxlbWVudHMgb2YgdGhlIG1hdHJpeDpcbiIpOwogICAgZm9yIChpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgIGZvciAoaiA9IDA7IGogPCBuOyBqKyspIHsKICAgICAgICAgICAgc2NhbmYoIiVkIiwgJm1hdHJpeFtpXVtqXSk7CiAgICAgICAgfQogICAgfQoKICAgIC8vIENhbGN1bGF0ZSB0cmFjZSBhbmQgbm9ybQogICAgZm9yIChpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgIHRyYWNlICs9IG1hdHJpeFtpXVtpXTsgLy8gc3VtIG9mIHByaW5jaXBhbCBkaWFnb25hbCBlbGVtZW50cwogICAgICAgIGZvciAoaiA9IDA7IGogPCBuOyBqKyspIHsKICAgICAgICAgICAgbm9ybSArPSBtYXRyaXhbaV1bal0gKiBtYXRyaXhbaV1bal07IC8vIHN1bSBvZiBzcXVhcmVzIG9mIGVsZW1lbnRzCiAgICAgICAgfQogICAgfQoKICAgIG5vcm0gPSBzcXJ0KG5vcm0pOyAvLyBTcXVhcmUgcm9vdCBvZiBzdW0gb2Ygc3F1YXJlcwoKICAgIHByaW50ZigiVHJhY2Ugb2YgdGhlIG1hdHJpeDogJWRcbiIsIHRyYWNlKTsKICAgIHByaW50ZigiTm9ybSBvZiB0aGUgbWF0cml4OiAlLjJmXG4iLCBub3JtKTsKCiAgICByZXR1cm4gMDsKfQoK