Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cmath>
- using namespace std;
- bool sorc(int a);
- int main() {
- int n;
- cout << "[Array] Size: "; cin >> n;
- int *p = new int[n];
- int count = 0, max = 0;
- cout << "Random | Elements of array:\n";
- for (int i = 0; i < n; i++) {
- cout << "P[" << i << "] = " << ( p[i] = rand()%10 ) << endl;
- if( sorc(p[i]) ) {
- count++;
- }
- }
- if (count > max) {
- max = count;
- }
- cout << max;
- delete [] p;
- }
- /*------------- voidblock ---------------*/
- bool sorc(int a) {
- int count = 0;
- if (a == 1) {
- return 0;
- }
- else {
- if (a == 2) {
- return 1;
- }
- else {
- for (int i = 1; i <= a; i++ ) {
- if (a % i == 0) {
- count++;
- }
- }
- if (count == 2) {
- return 1;
- } else {
- return 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment