Advertisement
Guest User

Untitled

a guest
Aug 31st, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include<math.h>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. bool premier(int x)
  9. {
  10. bool v(true);
  11. int i(2);
  12. if (x==2)
  13. {
  14. v=true;
  15. }
  16. else if (x==1)
  17. {
  18. v=false;
  19. }
  20. else{
  21.  
  22.  
  23. for(i=2;i<x-1;++i)
  24. {
  25. if (x%i==0)
  26. {
  27. v=false;
  28. }
  29. }
  30. }
  31. return v;
  32. }
  33.  
  34.  
  35.  
  36.  
  37. void saisie(int &n,vector<int>&(tab))
  38. {
  39. do
  40. {
  41.  
  42.  
  43. cout<<"n=";
  44. cin>>n;
  45. }
  46. while
  47. (n<3||n>10);
  48. int z(0);
  49. int i(0);
  50. for(i=0;i<n;++i)
  51. {
  52.  
  53.  
  54. do
  55. {
  56. cout<<"tab["<<i<<"]=";
  57. cin>>z;
  58. }
  59. while(z<10||z>=1000);
  60. tab.push_back(z);
  61. }
  62. }
  63.  
  64.  
  65.  
  66. bool riche(int z)
  67. {
  68. int i(1);
  69. bool v(false);
  70. do
  71. {
  72. i=i+1;
  73. if (z%(i*i)==0)
  74. {
  75. v=true;
  76. }
  77. }
  78. while((v==false)&&(i*i)<z);
  79.  
  80. return v;
  81. }
  82.  
  83.  
  84. void decomposition(int z)
  85. {
  86. int i(2),r(0);
  87. cout<<z<<"=";
  88. do
  89. {
  90.  
  91. if (premier(i)&&z%i==0)
  92. {
  93.  
  94.  
  95. cout<<i<<"*";
  96. z=z/i;
  97. r=i;
  98. }
  99. else
  100. {
  101. i=i+1;
  102. }
  103.  
  104. }
  105. while (premier(z)==false);
  106. cout<<z;
  107. cout<<endl;
  108.  
  109.  
  110. }
  111. void aff(int n,vector<int>(tab))
  112. {
  113. int i(0);
  114. cout<<"les nombres riches sont:"<<endl;
  115. for(i=0;i<n-1;++i)
  116. {
  117. if (riche(tab[i]))
  118. {
  119. cout<<tab[i]<<",";
  120. }
  121. }
  122. if (riche(tab[n-1]))
  123. {
  124. cout<<tab[n-1];
  125. }
  126. cout<<"en effet"<<endl;
  127. for (i=0;i<n-1;++i)
  128. {
  129. if (riche(tab[i]))
  130. {
  131. decomposition(tab[i]);
  132. }
  133. }
  134. }
  135.  
  136.  
  137.  
  138.  
  139.  
  140. int main()
  141. {
  142. int n(0);
  143. vector<int>tab;
  144. saisie(n,tab);
  145. aff(n,tab);
  146. return 0;
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement