ChameL1oN

Лаба5_Задача1(Вар.3)

Dec 14th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <locale>
  3. #include <fstream>
  4. #include <stdlib.h>
  5. #include <time.h>
  6.  
  7. using namespace std;
  8.  
  9. //Найти количество простых чисел в массиве.
  10. int* form_massive(int count){
  11. int* massive = new int[count];
  12. int a = 0;
  13. time_t t;
  14. srand((unsigned)time(&t));
  15. while (a < count){
  16. massive[a] = rand() % 100;
  17. cout << "massive [" << a << "] = " << massive[a] << endl;
  18. a++;
  19. }
  20. return massive;
  21. }
  22. void init_massive(int massive[], int count){
  23. int a = 0, i, j = 0, n = 0;
  24. int k = 0;
  25. while (n < count - 1){
  26. for (int i = 2; (i < massive[n] / 2) && (k == 0); i++)
  27. {
  28. if (massive[n] % i == 0){
  29. k++;
  30. }
  31. }
  32. if (k == 0){
  33. j++;
  34. }
  35. k = 0;
  36. n++;
  37. }
  38. cout << "Кол-во простых чисел в массиве равно : " << j << endl;
  39. }
  40.  
  41. void main(){
  42. int count, k;
  43. setlocale(LC_ALL, "rus");
  44. cout << "Введите кол-во элементов в массиве ";
  45. cin >> count;
  46. int* mas = form_massive(count);
  47. init_massive(mas, count);
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment