-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLab3.c
66 lines (55 loc) · 2.47 KB
/
Lab3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//empty comment
#include <stdio.h>
#include <math.h>
int matrix[7][7];
void insertionSortOfRowsByDescending()
{
extern int matrix[7][7];
int temporaryValue;
for (int k = 0; k < 5; k++)
{
for (int i = 1; i < 5; i++)
{
temporaryValue = matrix[k][i];
for (int j = i - 1; j >= 0; j--)
{
if (temporaryValue > matrix[k][j])
matrix[k][j + 1] = matrix[k][j];
else
break;
}
matrix[k][j + 1] = temporaryValue;
}
}
}
int sumOfElementsUnderMainDiag(int columnNumber)
{
int sumOfColumn = 0;
for (int i = columnNumber + 1; i < 5; i++)
sumOfColumn += matrix[i][columnNumber];
return sumOfColumn;
}
int main()
{
extern int matrix[7][7];
for (int i = 0; i < 5; i++)
for (int j = 0; j < 5; j++)
scanf_s("%d", &matrix[i][j]);
insertionSortOfRowsByDescending();
printf("\n\n");
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
printf("%4d ", matrix[i][j]);
printf("\n");
}
printf("\n\n");
int geometricMean = 1;
for (int i = 0; i < 4; i++)
{
int sumOfElements = int sumOfElementsUnderMainDiag(i);
geometricMean *= sumOfElements;
printf("%d ", sumOfElements);
}
printf("\n%lf\n", pow(abs(geometricMean), 1.0/4.0));
}