Advertisement
Guest User

cifre003

a guest
Nov 13th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int n,nr,cn,s,uc,restulLuiSla3;
  5. int main()
  6. {
  7. cin>>n;
  8. cn=n;
  9. while(cn)
  10. {
  11. s=s+cn%10;
  12. cn=cn/10;
  13. }
  14. restulLuiSla3=s%3;
  15. //practic daca suma cifrelor nr meu are restul R cand o impart la 3,
  16. // atunci pot elimina orice cifra care are restul R la impartirea prin 3
  17. while(n){
  18. uc=n%10;
  19. if(uc%3==restulLuiSla3)
  20. nr++;
  21. n=n/10;
  22. }
  23. cout<<nr;
  24. return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement