Advertisement
thinhckhcmus

So Dao Nguoc

Aug 5th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #define MAX 1000000
  3. using namespace std;
  4. void nhapsonguyenduong(int &n)
  5. {
  6. do
  7. {
  8. cout << "nhap so nguyen duong de kiem tra = ";
  9. cin >> n;
  10. if (n<0 || n>MAX)
  11. {
  12. cout << " so khong hop le, xin moi nhap lai";
  13. }
  14. } while ((n < 0) || (n > MAX));
  15.  
  16. }
  17. int sodaonguoc(int &n)
  18. {
  19. int daonguoc = 0;
  20. int phantu;
  21. while (n > 0)
  22. {
  23. phantu = n % 10;
  24. daonguoc = daonguoc * 10 + phantu;
  25. n = n / 10;
  26. }
  27. return daonguoc;
  28. }
  29. void main()
  30. {
  31. int n;
  32. nhapsonguyenduong(n);
  33. cout << "so dao nguoc la: " << sodaonguoc(n) << endl;
  34. system("pause");
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement