Advertisement
phongtv-ce

So 3 chu so

Sep 28th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int n, tmp, sum;
  7.     do
  8.     {
  9.         cout << "Nhap mot so co 3 chu so: ";
  10.         cin >> n;
  11.         if(n<100 || n>999)
  12.             cout << "Khong thoa yeu cau, nhap lai!"<< endl;
  13.     }while(n<100 || n>999);
  14.    
  15.     sum=0;
  16.     tmp=n;
  17.     while(tmp>0)
  18.     {
  19.         sum += tmp % 10;
  20.         tmp /= 10;
  21.     }
  22.    
  23.     cout << "Tong cac chu so la: "<< sum << endl;
  24.     cout << "Chu so hang tram "<< n/100
  25.          << " hang chuc " << n/10%10
  26.          << " hang don vi " << n%10 << endl;
  27.    
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement