Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- const int ILLEGAL_INPUT = -1;
- int MixNewNum(int num);
- void main()
- {
- int num;
- int res;
- cout << "Please enter a natural numbers: ";
- cin >> num;
- res = MixNewNum(num);
- if (res != ILLEGAL_INPUT)
- cout << "The new number is : " << res << endl;
- else
- cout << "Eror!!The input is illegal! "<< endl;
- }
- int MixNewNum(int num)
- {
- if (num <= 0)
- return ILLEGAL_INPUT;
- int res;
- int digit1, digit2;
- int temp_num;
- int mult;
- mult = 1;
- res = 0;
- if (num > 9)
- {
- while (num > 9)
- {
- digit1 = num % 10;
- num /= 10;
- digit2 = num % 10;
- num /= 10;
- temp_num = (digit1 * 10) + (digit2);
- res = res + (temp_num*mult);
- mult *= 100;
- }
- res = res + (num*mult);
- }
- else
- {
- res = num;
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement