Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n, tmp, sum;
- do
- {
- cout << "Nhap mot so co 3 chu so: ";
- cin >> n;
- if(n<100 || n>999)
- cout << "Khong thoa yeu cau, nhap lai!"<< endl;
- }while(n<100 || n>999);
- sum=0;
- tmp=n;
- while(tmp>0)
- {
- sum += tmp % 10;
- tmp /= 10;
- }
- cout << "Tong cac chu so la: "<< sum << endl;
- cout << "Chu so hang tram "<< n/100
- << " hang chuc " << n/10%10
- << " hang don vi " << n%10 << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement