Advertisement
Razk2108

E1-H2-PUNTEROS

May 29th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5. using namespace System;
  6.  
  7. void menu()
  8. {
  9.     cout << "Menu de opciones\n\n";
  10.     cout << "1.Determinar el factorial de un numero\n";
  11.     cout << "2.Calcular el valor de e^a\n";
  12.     cout << "3.Imprime rombo\n";
  13.     cout << "4.Fin\n";
  14. }
  15. float factorial(int n)
  16. {
  17.     float fact = 1;
  18.     int c;
  19.     for (c = 1;c <= n;c++)
  20.         fact = fact*c;
  21.     return fact;
  22. }
  23. float exponencial(float a, int k)
  24. {
  25.     float suma = 0;
  26.     for (int c = 0;c <= k;c++)
  27.         suma = suma + pow(a, c) / factorial(c);
  28.     return suma;
  29. }
  30. void dibuja(int n)
  31. {
  32.     int fila, c, blancos;
  33.     for (fila = 1;fila <= n;fila++)
  34.     {
  35.         blancos = n - fila;
  36.         for (c = 1;c <= blancos;c++)
  37.             cout << " ";
  38.         for (c = 1;c <= 2 * fila-1;c++)
  39.             cout << c;
  40.         cout << endl;
  41.     }
  42.     for (fila = n - 1;fila >= 1;fila--)
  43.     {
  44.         blancos = n - fila;
  45.         for (c = 1;c <= blancos;c++)
  46.             cout << " ";
  47.         for (c = 1;c <= 2 * fila - 1;c++)
  48.             cout << c;
  49.         cout << endl;
  50.     }
  51. }
  52. void main()
  53. {
  54.     int n, k, opcion;
  55.     float a;
  56.     do
  57.     {
  58.         Console::Clear();
  59.         menu();
  60.         do
  61.         {
  62.             cout << "Ingrese su opcion:";cin >> opcion;
  63.         }while(opcion<1||opcion>4);
  64.         if (opcion != 4)
  65.         {
  66.             Console::Clear();
  67.             switch (opcion)
  68.             {
  69.             case 1:cout << "Calculo del factorial\n";
  70.                 do
  71.                 {
  72.                     cout << "Ingrese el valor de N:";
  73.                 } while (n < 0);
  74.                 cout << "Facotorial=" << factorial(n) << endl;
  75.                 break;
  76.             case 2:cout << "Calculo del exponencial\n";
  77.                 cout << "Ingrese el valor de a\n";cin >> a;
  78.                 do
  79.                 {
  80.                     cout << "Ingrese el valor de k\n";cin >> k;
  81.                 } while (k<0||k>20);
  82.                 cout << "Exponencial=" << exponencial(a, k) << endl;
  83.                 break;
  84.             case 3:cout << "Dibujo del Rombo\n";
  85.                 do
  86.                 {
  87.                     cout << "Ingrese el valor de N\n";cin >> n;
  88.                 } while (n<1||n>10);
  89.                 dibuja(n);
  90.                 cout << endl;
  91.             }
  92.             cout << "Presione una tecla para continuar";
  93.             _getch();
  94.         }
  95.     } while (opcion != 4);
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement