Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace System;
- using namespace std;
- int n_div[100];
- void validar(int*n)
- {
- do
- {
- cout << endl << "Ingrese el numero de eventos : ";
- cin >> *n;
- system("cls");
- } while (*n <= 20);
- }
- void primo(int *n , int *p) {
- int cont=0;
- for (int i = 1; i<= *n ; i++) {
- if (*n %i == 0) {
- cont++;
- }
- }
- if (cont <= 2) {
- *p = *n-1;
- }
- else *p = *n;
- }
- void divisores(int *p,int *i , int *j )
- {
- int cont = 0;
- for (int f = 1; f <= *p; f++) {
- if (*p %f == 0) {
- n_div[cont] = f;//se guardo los divisores
- cont++; // posicion del elemento
- }
- }
- int medio = cont / 2; // hallar la posicion del medio
- *i = n_div[medio]; // numero de columnas
- *j = *p/ n_div[medio]; // numero de filas
- }
- void mapa(int *i, int *j)
- {
- for (int f = 0; f < *i; f++) {
- for (int c = 0; c < *j; c++) {
- Console::SetCursorPosition(f, c);
- if (f % 2 == 0 && c % 2 == 0) {
- Console::ForegroundColor = ConsoleColor::White;
- cout << char(219);
- }
- if (f % 2 == 0 && c % 2 == 1) {
- Console::ForegroundColor = ConsoleColor::Blue;
- cout << char(219);
- }
- if (f % 2 == 1 && c % 2 == 0) {
- Console::ForegroundColor = ConsoleColor::Red;
- cout << char(219);
- }
- if (f % 2 == 1 && c % 2 == 1) {
- Console::ForegroundColor = ConsoleColor::Green;
- cout << char(219);
- }
- }
- }
- cout << endl;
- }
- void mapa_primo(int*p, int *n, int *i, int *j)
- {
- if (*p + 1 == *n) {
- for (int f = *i + 1; f >= *i; f--) {
- Console::SetCursorPosition(0, *j);
- for (int c = 1; c <= *i; c++) {
- if (*j % 2 == 0) {
- Console::ForegroundColor = ConsoleColor::White;
- cout << char(219);}
- else {
- Console::ForegroundColor = ConsoleColor::Blue;
- cout << char(219);}
- }
- }
- }
- }
- int main()
- {
- int *p = new int; int *n = new int; int *i = new int; int *j = new int;
- validar(n);
- primo(n, p);
- divisores(p, i, j);
- cout << endl << endl;
- mapa(i, j);
- mapa_primo(p, n, i, j);
- _getch();
- main();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement