Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // поиск простых чисел в массиве
- #include <conio.h>
- #include <iostream>
- using namespace std;
- #include <iomanip>
- #include <stdlib.h>
- #include <time.h>
- #include <math.h>
- bool prosto(int c)
- {
- bool flag=true;
- if ((c=0)|(c=1)) return false;
- for(int i=2;i<c;i++)
- {
- if (c%i==0) return false;
- }
- return flag;
- }
- void main()
- {
- const int n=5;
- int a[n];
- srand(0);
- srand((unsigned int)time(NULL));
- for (int i=0;i<n;i++) a[i]=rand()%100;
- for (int i=0;i<n;i++) cout<<"a["<<i<<"]="<<a[i]<<endl;
- cout<<"chislo prostux elementov v massive"<<endl;
- int ch=0;
- for (int i=0;i<n;i++)
- {
- if(prosto(a[i])==true) ch++;
- }
- cout<<ch;
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment