Advertisement
Ana_h

matematica discreta

Sep 17th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace System;
  5. using namespace std;
  6.  
  7.  
  8. int n_div[100];
  9.  
  10. void validar(int*n)
  11. {
  12.     do
  13.     {
  14.         cout << endl << "Ingrese el numero de eventos : ";
  15.         cin >> *n;
  16.         system("cls");
  17.     } while (*n <= 20);
  18. }
  19.  
  20. void  primo(int *n ,  int *p) {
  21.     int cont=0;
  22.  
  23.         for (int i = 1; i<= *n ; i++) {
  24.             if (*n %i == 0) {
  25.                 cont++;
  26.             }
  27.         }
  28.         if (cont <= 2) {
  29.             *p = *n-1;
  30.         }
  31.         else *p = *n;
  32.  
  33.     }
  34.  
  35.  
  36. void divisores(int *p,int *i , int *j  )
  37. {
  38.  
  39.     int cont = 0;
  40.     for (int f = 1; f <= *p; f++) {
  41.         if (*p %f == 0) {
  42.             n_div[cont] = f;//se guardo los divisores
  43.             cont++;   // posicion del elemento
  44.                    
  45.         }
  46.     }
  47.  
  48.     int medio  = cont / 2; // hallar la posicion del medio
  49.  
  50.     *i = n_div[medio];  // numero de columnas  
  51.     *j = *p/ n_div[medio]; // numero de filas
  52. }
  53.  
  54.  
  55. void mapa(int *i, int *j)
  56. {
  57.     for (int f = 0; f < *i; f++) {
  58.         for (int c = 0; c < *j; c++) {
  59.             Console::SetCursorPosition(f, c);
  60.             if (f % 2 == 0 && c % 2 == 0) {
  61.                 Console::ForegroundColor = ConsoleColor::White;
  62.                 cout << char(219);
  63.             }
  64.             if (f % 2 == 0 && c % 2 == 1) {
  65.                 Console::ForegroundColor = ConsoleColor::Blue;
  66.                 cout << char(219);
  67.             }
  68.             if (f % 2 == 1 && c % 2 == 0) {
  69.                 Console::ForegroundColor = ConsoleColor::Red;
  70.                 cout << char(219);
  71.             }
  72.             if (f % 2 == 1 && c % 2 == 1) {
  73.                 Console::ForegroundColor = ConsoleColor::Green;
  74.                 cout << char(219);
  75.             }
  76.         }
  77.     }
  78.     cout << endl;
  79. }
  80.  
  81. void mapa_primo(int*p, int *n, int *i, int *j)
  82. {
  83. if (*p + 1 == *n) {
  84.                 for (int f = *i + 1; f >= *i; f--) {
  85.                     Console::SetCursorPosition(0, *j);
  86.                     for (int c = 1; c <= *i; c++) {
  87.                         if (*j % 2 == 0) {
  88.                             Console::ForegroundColor = ConsoleColor::White;
  89.                             cout << char(219);}
  90.                         else {
  91.                             Console::ForegroundColor = ConsoleColor::Blue;
  92.                             cout << char(219);}
  93.             }
  94.         }
  95.     }
  96. }
  97. int main()
  98. {
  99.     int *p = new int; int *n = new int;  int *i = new int;   int *j = new int;
  100.         validar(n);
  101.         primo(n, p);
  102.         divisores(p, i, j);
  103.         cout << endl << endl;
  104.         mapa(i, j);
  105.         mapa_primo(p, n, i, j);
  106.         _getch();
  107.  
  108.         main();
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement