Advertisement
Guest User

porqueria de codigo

a guest
May 22nd, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace System;
  6. using std::cout;
  7. using std::cin;
  8. using std::endl;
  9.  
  10. short menu() {
  11.     short *opcion = new short;
  12.     do {
  13.         cout << "1-Determinar el factorial de un numero : " << endl;
  14.         cout << "2-Calcular de e^a : " << endl;
  15.         cout << "3-Imprimir Rombo : " << endl;
  16.         cout << "4-Salir : " << endl;
  17.         cin >> *opcion;
  18.     } while (*opcion < 1 || *opcion>4);
  19.     return *opcion;
  20. }
  21. long factorial(short *nro) {
  22.     short c = 1;
  23.     long factorial(1);
  24.     do {
  25.         factorial *= c;
  26.             ++c;
  27.     } while (c <= *nro);
  28.     return factorial;
  29. }
  30. long potencia(short *b, short *exp) {
  31.     long r = 1;
  32.     for (int c = 1; c <= *exp; ++c)
  33.     {
  34.         r *= *b;
  35.     }
  36.     return r;
  37. }
  38. void sumatoria(short *a, short *k){
  39.     float r = 1;
  40.     for (short c = 1; c <= *k; ++c)
  41.         r += (float)potencia(a, &c) / (float)factorial(&c);
  42.     cout << r;
  43. }
  44. void graficar(int l) {
  45.    
  46.     for (short cf = 1; cf<= l; cf++)  
  47.     {Console::SetCursorPosition(40-cf-1, cf);
  48.         for (short cc = 1; cc <= 2*cf-1; cc++)
  49.         {
  50.            
  51.             cout << cc;
  52.         }
  53.         cout<<endl;
  54.     }
  55.     //////
  56.     for (short cf = 1; cf <= l; cf++)
  57.     {
  58.         Console::SetCursorPosition(40 - cf-1 , 2*l-cf);
  59.         for (short cc = 1; cc <= 2 * cf - 1; cc++)
  60.         {
  61.  
  62.             cout << cc;
  63.         }
  64.         cout << endl;
  65.     }
  66. }
  67. short ingresarNro() {
  68.     short nro;
  69.     do{
  70.         cout << "ingrese nro : ";
  71.         cin >> nro;
  72.     } while (nro < 0 || nro>10);
  73.     return nro;
  74. }
  75. int main() {
  76.     short op = menu();
  77.     short *nro = new short;
  78.     short *a = new short;
  79.     short *k = new short;
  80.     float *suma;
  81.     switch (op) {
  82.     case 1:
  83.         *nro=ingresarNro();
  84.         cout << "El factorial es : " << factorial(nro);break;
  85.     case 2:
  86.         *a = ingresarNro();
  87.         *k = ingresarNro();
  88.         sumatoria(a, k);break;
  89.     case 3:
  90.         *nro = ingresarNro();
  91.         graficar(*nro);
  92.     default:;
  93.                }
  94.    
  95.    
  96.  
  97.     cin.ignore();
  98.     cin.get();
  99.     return 0;
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement