Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. #1 numere prime
  2.  
  3. #include<iostream>
  4. using namespace std;
  5. int main()
  6. {
  7. int n,c=0;
  8. cout<<"Introdu n"; cin>>n;
  9. for (int i=1; i<=n; i++)
  10. {
  11. if (n%i==0)
  12. c++;
  13. }
  14. if (c==2)
  15. cout<<"Numarul este prim";
  16. else
  17. cout<<"Numarul NU este prim";
  18. return 0;
  19. }
  20.  
  21. #2 lista numere prime
  22.  
  23. #include <iostream>
  24. #include <math.h>
  25.  
  26. using namespace std;
  27.  
  28. int main()
  29. {
  30. int i,x,d,OK;
  31. cin >> x;
  32. if (x>1)
  33. {
  34. cout << 2 << ' ';
  35. for (i = 3 ; i<=x ; i = i+2)
  36. {
  37. OK = 1;
  38. for (d = 3 ; d <= sqrt(i) and OK == 1; d = d+2)
  39. if (i % d == 0)
  40. OK = 0;
  41. if (OK==1)
  42. cout << i << ' ';
  43. }
  44. }
  45. return 0;
  46. }
  47.  
  48. #3 primele n numere prime
  49.  
  50. #include <iostream>
  51. #include <math.h>
  52.  
  53. using namespace std;
  54.  
  55. int main()
  56. {
  57. int i,x,d,OK;
  58. cin >> x;
  59. if (x>1)
  60. {
  61. cout << 2 << ' ';
  62. for (i = 3 ; i<=x ; i = i+2)
  63. {
  64. OK = 1;
  65. for (d = 3 ; d <= sqrt(i) and OK == 1; d = d+2)
  66. if (i % d == 0)
  67. OK = 0;
  68. if (OK==1)
  69. cout << i << ' ';
  70. }
  71. }
  72. return 0;
  73. }
  74.  
  75. #4 afisarea unui numar cu o subdiviziune
  76.  
  77. #include<iostream>
  78. #include<math.h>
  79. using namespace std;
  80. int main()
  81. {
  82. int n, k;
  83. int copien;
  84. cout<<"n=";
  85. cin>>n;
  86. if(n<0){n=n*(-1);}
  87. copien=n-1;
  88. cout<<"numarul cel mai mare mai mic decat "<<n<<" este = "<<copien;
  89.  
  90. return 0;
  91. }
  92.  
  93. #5 desc.
  94. #include<iostream>
  95. using namespace std;
  96.  
  97.  
  98. int x;
  99. int cifre;
  100.  
  101. int main()
  102. {
  103. cout<<"x=";cin>>x;
  104. while(x>10){
  105. x=x/10;
  106. x++;}
  107. cout<<"x=" <<x;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement