AddO1f

Мясной рулетик

Apr 9th, 2016
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4. #include <cstdlib>
  5.  
  6. int poisk(int a);
  7. bool del(int* a, int &n);
  8.  
  9. using namespace std;
  10.  
  11. int _tmain(int argc, _TCHAR* argv[])
  12. {
  13.     setlocale( LC_ALL,"Russian" );
  14.     int n,ma,k=0,sum=0;
  15.     cout << "Введите размер: ";
  16.     cin >> n;
  17.     int* a =new int[n];
  18.     cout << "Введите массив: ";
  19.     for (ma=0; ma<n; ma++)
  20.     {
  21.         cin >> a[ma];
  22.         poisk(a[ma]);
  23.         if (poisk(a[ma])==true) {k=k+1;}
  24.         else if (k>1) {sum=sum+1; k=0;}
  25.     }
  26.     if (k>1) {sum=sum+1;}
  27.     del(a,n);
  28.     cout<<"Количество серий простых чисел первого массива: "<<sum<<endl;
  29.     sum=k=0;
  30.     cout<<"Второй массив: ";
  31.     for (ma=0; ma<n; ma++)
  32.     {
  33.         cout << a[ma] <<" ";
  34.         poisk(a[ma]);
  35.         if (poisk(a[ma])==true) {k=k+1;}
  36.         else if (k>1) {sum=sum+1; k=0;}
  37.     }
  38.     if (k>1) {sum=sum+1;}
  39.     cout<<endl<<"Количество серий простых чисел второго массива: "<<sum<<endl;
  40.     system("pause");
  41. }
  42.  
  43. int poisk(int a)
  44. {
  45.     int i;
  46.     if(a==1) return false;
  47.     for(i=2; i*i<=a; i++)
  48.     {
  49.         if(a%i==0)
  50.         return false;
  51.     }
  52.     return true;
  53. }
  54.  
  55. bool del(int* a, int &n)
  56. {
  57.     int k=0,p=0,ma;
  58.     for (ma=0; ma<n; ma++)
  59.     {
  60.         if (a[ma]<=9) {a[k]=a[ma];k++;}
  61.     }
  62.     n=k;
  63.     return true;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment