Advertisement
thinhckhcmus

Chữ Số Lớn Nhất

Aug 12th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include<iostream>
  2. #include<iomanip>
  3. using namespace std;
  4.  
  5. void NhapSoNguyenDuong(int &num)
  6. {
  7. do
  8. {
  9. cout << "\nEnter number: ";
  10. cin >> num;
  11. if ((num <= 1) || (num >= 10000000))
  12. cout << "\nMoi ban nhap lai";
  13. } while ((num <= 1) || (num >= 10000000));
  14. }
  15. int ChuSoLonNhat(int num)
  16. {
  17. int Max = num % 10;
  18. int phantu;
  19. while (num)
  20. {
  21. num /= 10;
  22. phantu = num % 10;
  23. if (phantu > Max)
  24. Max = phantu;
  25. }
  26. return Max;
  27. }
  28. int main()
  29. {
  30. int num;
  31. NhapSoNguyenDuong(num);
  32. cout << "So lon nhat trong chuoi so nhap vao la: " << ChuSoLonNhat(num) << endl;
  33. system("pause");
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement