Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int summa(int n) {
- int summa = 0;
- while (n != 0) {
- summa += n % 10; n /= 10;
- }
- return summa;
- }
- int main() {
- int n;
- cin >> n;
- int A[n];
- for (int i = 0; i < n; i++)
- cin >> A[i];
- for (int X = 0; X < n; X++)
- for (int j = n - 1; j > X; j--)
- if (summa(A[j]) > summa(A[j - 1]))
- swap(A[j], A[j - 1]);
- for (int Z = 0; Z < n; Z++)
- cout << A[Z] << " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement