Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication1.cpp : main project file.
- #include "stdafx.h"
- #include <conio.h>
- #include <iostream>
- using namespace std;
- using namespace System;
- bool Es_Primo(int x)
- {
- int cont = 0;
- for (int pdiv = 1; pdiv <= x; pdiv++)
- {
- if (x%pdiv == 0)
- cont++;
- }
- if (cont == 2)
- return true; else return false;
- }
- int main()
- {
- int n, npa=0, npr=0;
- Random x;
- do {
- cout << "Ingrese un numero positivo. " << endl;
- cin >> n;
- } while (n <= 0);
- int *a = new int[n];
- for (int i = 0; i < n; i++)
- {
- a[i] = x.Next(10, 10001);
- if (a[i] % 2 == 0)npa++;
- if (Es_Primo(a[i]) == true)npr++;
- }
- int *APAR = new int[npa];
- int j = 0;
- for (int i = 0; i < n; i++)
- {
- if (a[i] % 2 == 0)
- {
- APAR[j] = a[i];
- j++;
- }
- }
- j = 0;
- int *APRIMO = new int[npr];
- for (int i = 0; i < n; i++)
- {
- if (Es_Primo(a[i]) == true)
- {
- APRIMO[j] = a[i];
- j++;
- }
- }
- for (int i = 0; i < npr; i++)
- cout << APRIMO[i] << " ";
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment