Guest User

Untitled

a guest
Dec 23rd, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. // поиск простых чисел в массиве
  2. #include <conio.h>
  3. #include <iostream>
  4. using namespace std;
  5. #include <iomanip>
  6. #include <stdlib.h>
  7. #include <time.h>
  8. #include <math.h>
  9. bool prosto(int c)
  10. {
  11. bool flag=true;
  12. if ((c=0)|(c=1)) return false;
  13. for(int i=2;i<c;i++)
  14. {
  15. if (c%i==0) return false;
  16. }
  17. return flag;
  18.  
  19. }
  20. void main()
  21. {
  22. const int n=5;
  23. int a[n];
  24. srand(0);
  25. srand((unsigned int)time(NULL));
  26. for (int i=0;i<n;i++) a[i]=rand()%100;
  27. for (int i=0;i<n;i++) cout<<"a["<<i<<"]="<<a[i]<<endl;
  28. cout<<"chislo prostux elementov v massive"<<endl;
  29. int ch=0;
  30. for (int i=0;i<n;i++)
  31. {
  32. if(prosto(a[i])==true) ch++;
  33. }
  34. cout<<ch;
  35. _getch();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment