-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProblem-4.c
More file actions
39 lines (39 loc) · 690 Bytes
/
Copy pathProblem-4.c
File metadata and controls
39 lines (39 loc) · 690 Bytes
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
#include <stdio.h>
void sort(int *arr, int n)
{
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (arr[j] < arr[j + 1])
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
int power(int a)
{
if (a == 0)
return 1;
return 3 * power(a - 1);
}
int main()
{
int n;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++)
{
scanf("%d", &arr[i]);
}
sort(arr, n);
int ans = 0;
for (int i = 0; i < n; i++)
{
ans += power(i) * arr[i];
}
printf("%d", ans);
}