Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. /*
  2.  
  3. EXERCITIUL NUMARUL 2
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int oglinda(int x)
  8. {
  9. int aux=0;
  10. while(x){
  11. aux=aux*10+x%10;
  12. x/=10;
  13.  
  14. }
  15. return aux;
  16. }
  17.  
  18. int main()
  19. {
  20. cout<<oglinda(1234);
  21.  
  22. return 0;
  23. }
  24.  
  25. EXERCITIUL NUMARUL 3
  26. #include <iostream>
  27. using namespace std;
  28.  
  29. int maxim(int x)
  30. {
  31. int V[15],n=0, ok, aux, nr=0;
  32.  
  33. while(x){
  34. V[++n]=x%10;
  35. x/=10;
  36. }
  37.  
  38. do{
  39. ok=1;
  40. for(int i=1;i<n;i++)
  41. if(V[i]<V[i+1]){
  42. aux=V[i];
  43. V[i]=V[i+1];
  44. V[i+1]=aux;
  45. ok=0;
  46. }
  47. }while(!ok);
  48.  
  49. for(int i=1;i<=n;i++)
  50. nr=nr*10+V[i];
  51.  
  52. return nr;
  53. }
  54.  
  55. int main()
  56. {
  57. cout<<maxim(93678);
  58.  
  59. return 0;
  60. }
  61.  
  62. EXERCITIUL NUMARUL 4
  63. #include <iostream>
  64. #include <math.h>
  65. using namespace std;
  66.  
  67. int concat(int a, int b)
  68. {
  69. int c1=0, aux, nr;
  70.  
  71.  
  72. aux=b;
  73. while(aux){
  74. c1++;
  75. aux/=10;
  76. }
  77.  
  78.  
  79. nr=a*pow(10, c1)+b;
  80.  
  81. return nr;
  82. }
  83.  
  84. int main()
  85. {
  86. cout<<concat(123, 321);
  87.  
  88. return 0;
  89. }
  90.  
  91. EXERCITIUL NUMARUL 5
  92. #include <iostream>
  93. using namespace std;
  94.  
  95. int nr_prim(int a)
  96. {
  97. int i,ok=1;
  98.  
  99. for(i=2;i*i<=a&&ok==1;i++)
  100. if(a%i==0)
  101. ok=0;
  102.  
  103. return ok;
  104. }
  105.  
  106. int main()
  107. {
  108. if(nr_prim(123))
  109. cout<<"Numarul este prim!";
  110. else
  111. cout<<"Numarul nu este prim!";
  112.  
  113.  
  114. return 0;
  115. }
  116.  
  117. EXERCITIUL NUMARUL 6
  118. #include <iostream>
  119. using namespace std;
  120.  
  121. int s_div(int a)
  122. {
  123. int i,s=0;
  124. for(i=2;i<=a;i++)
  125. if(a%i==0)
  126. s+=i;
  127.  
  128. return s;
  129. }
  130.  
  131. int main()
  132. {
  133. cout<<s_div(10);
  134.  
  135. return 0;
  136. }
  137. EXERCITIUL NUMARUL 7
  138.  
  139. #include <iostream>
  140. using namespace std;
  141.  
  142. int nr_zero(int a)
  143. {
  144. int c=0;
  145.  
  146. while(a){
  147. if(a%10 == 0)
  148. c++;
  149. a/=10;
  150. }
  151.  
  152. return c;
  153. }
  154.  
  155. int main()
  156. {
  157. cout<<nr_zero(10293010);
  158.  
  159. return 0;
  160. }
  161. EXERCITIUL NUMARUL 8
  162.  
  163. #include <iostream>
  164. using namespace std;
  165.  
  166. void ulc_para(int a)
  167. {
  168. int gasit=0;
  169.  
  170. while(a && !gasit){
  171. if((a%10)%2 == 0)
  172. gasit=1;
  173. else
  174. a/=10;
  175. }
  176.  
  177. if(gasit)
  178. cout<<"Ultima cifra para este: "<<a%10;
  179. else
  180. cout<<"Nu exista numere pare!";
  181. }
  182.  
  183. int main()
  184. {
  185. ulc_para(11111);
  186.  
  187. return 0;
  188. }
  189.  
  190.  
  191. EXERCITIUL NUMARUL 9
  192.  
  193. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement