Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <math.h>
- #include <cstdlib>
- int poisk(int a);
- bool del(int* a, int &n);
- using namespace std;
- int _tmain(int argc, _TCHAR* argv[])
- {
- setlocale( LC_ALL,"Russian" );
- int n,ma,k=0,sum=0;
- cout << "Введите размер: ";
- cin >> n;
- int* a =new int[n];
- cout << "Введите массив: ";
- for (ma=0; ma<n; ma++)
- {
- cin >> a[ma];
- poisk(a[ma]);
- if (poisk(a[ma])==true) {k=k+1;}
- else if (k>1) {sum=sum+1; k=0;}
- }
- if (k>1) {sum=sum+1;}
- del(a,n);
- cout<<"Количество серий простых чисел первого массива: "<<sum<<endl;
- sum=k=0;
- cout<<"Второй массив: ";
- for (ma=0; ma<n; ma++)
- {
- cout << a[ma] <<" ";
- poisk(a[ma]);
- if (poisk(a[ma])==true) {k=k+1;}
- else if (k>1) {sum=sum+1; k=0;}
- }
- if (k>1) {sum=sum+1;}
- cout<<endl<<"Количество серий простых чисел второго массива: "<<sum<<endl;
- system("pause");
- }
- int poisk(int a)
- {
- int i;
- if(a==1) return false;
- for(i=2; i*i<=a; i++)
- {
- if(a%i==0)
- return false;
- }
- return true;
- }
- bool del(int* a, int &n)
- {
- int k=0,p=0,ma;
- for (ma=0; ma<n; ma++)
- {
- if (a[ma]<=9) {a[k]=a[ma];k++;}
- }
- n=k;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment