Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <locale>
- #include <fstream>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- //Найти количество простых чисел в массиве.
- int* form_massive(int count){
- int* massive = new int[count];
- int a = 0;
- time_t t;
- srand((unsigned)time(&t));
- while (a < count){
- massive[a] = rand() % 100;
- cout << "massive [" << a << "] = " << massive[a] << endl;
- a++;
- }
- return massive;
- }
- void init_massive(int massive[], int count){
- int a = 0, i, j = 0, n = 0;
- int k = 0;
- while (n < count - 1){
- for (int i = 2; (i < massive[n] / 2) && (k == 0); i++)
- {
- if (massive[n] % i == 0){
- k++;
- }
- }
- if (k == 0){
- j++;
- }
- k = 0;
- n++;
- }
- cout << "Кол-во простых чисел в массиве равно : " << j << endl;
- }
- void main(){
- int count, k;
- setlocale(LC_ALL, "rus");
- cout << "Введите кол-во элементов в массиве ";
- cin >> count;
- int* mas = form_massive(count);
- init_massive(mas, count);
- }
Advertisement
Add Comment
Please, Sign In to add comment