Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- int dSum ( int num )
- {
- int sum = 0;
- num = abs(num);
- while ( num > 0 )
- {
- sum += num % 10;
- num /= 10;
- }
- return sum;
- }
- int main ( int argc, char * argv[] )
- {
- cout << "Zadejte n:" << endl;
- int n;
- cin >> n;
- if ( cin.fail() || n <= 0 )
- {
- cout << "Nespravny vstup" << endl;
- return 1;
- }
- cout << "Zadejte cisla" << endl;
- int c = 0, tmp;
- for ( ; n != 0; n-- )
- {
- cin >> tmp;
- if ( cin.fail() )
- {
- cout << "Nespravny vstup" << endl;
- return 1;
- }
- if ( dSum(tmp) > dSum(c) )
- c = tmp;
- if ( dSum(tmp) == dSum(c) && tmp > c )
- c = tmp;
- }
- cout << "Vysledek: " << c << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment