Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n, s = 0, q = 0, number,p = 0;
  8. cout<<"Introduceti un numar componentele caruia sunt numere naturale nenule: "<<endl;
  9. cin>>n;
  10. int b =n;
  11. while(b)
  12. {
  13. b = b/10;
  14. q++;
  15.  
  16. }
  17. int*a = new int[q];
  18. int c = n;
  19. while(c)
  20. { int k = 0;
  21. number = c%10;
  22. for(int i = 2;i<number;i++)
  23. {
  24. if(number%i==0)
  25. k++;
  26. }
  27. if(k==0)
  28. {
  29. a[p] = number;
  30. p++;
  31. }
  32. c=c/10;
  33. }
  34. for(int i =0;i<=p;i++)
  35. { int r = 0;
  36. for(int j = i+1;j<=p;j++)
  37. {
  38.  
  39. if(a[i] == a[j])
  40. r++;
  41. }
  42. if(r==0)
  43. s+=a[i];
  44. }
  45.  
  46. cout<<s<<endl;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement