Advertisement
Guest User

Untitled

a guest
Nov 9th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. void init(int& n);
  3. bool isPrime(int x);
  4. int result(int n);
  5. void coutResult(int t);
  6.  
  7.  
  8. int main() {
  9. int n;
  10. init(n);
  11. int t = result(n);
  12. coutResult(t);
  13. }
  14.  
  15. void init(int& n) {
  16. scanf("%d", &n);
  17. }
  18.  
  19. bool isPrime(int x) {
  20. if (x == 1 || x == 0) return false;
  21. for (int i = 2; i < x; i++) {
  22. if (x % i == 0) return false;
  23. }
  24. return true;
  25. }
  26. int result(int n) {
  27. int count = 0;
  28. while (n > 0) {
  29. int x = n % 10;
  30. if (isPrime(x)) count++;
  31. n /= 10;
  32. }
  33. return count;
  34. }
  35.  
  36. void coutResult(int t) {
  37. printf("%d", t);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement