Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #define MAX 1000000
- using namespace std;
- void nhapsonguyenduong(int &n)
- {
- do
- {
- cout << "nhap so nguyen duong de kiem tra = ";
- cin >> n;
- if (n<0 || n>MAX)
- {
- cout << " so khong hop le, xin moi nhap lai";
- }
- } while ((n < 0) || (n > MAX));
- }
- int sodaonguoc(int &n)
- {
- int daonguoc = 0;
- int phantu;
- while (n > 0)
- {
- phantu = n % 10;
- daonguoc = daonguoc * 10 + phantu;
- n = n / 10;
- }
- return daonguoc;
- }
- void main()
- {
- int n;
- nhapsonguyenduong(n);
- cout << "so dao nguoc la: " << sodaonguoc(n) << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement