Advertisement
Guest User

yatamosya sistemista

a guest
May 24th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include <iomanip>
  7.  
  8. using namespace std;
  9.  
  10. void Ffactorial()
  11. {
  12.     int n;
  13.     int factorial = 1;
  14.    
  15.     int *p;
  16.     p = new int;
  17.    
  18.     do
  19.     {
  20.         cout << "Ingrese un numero positivo: "; cin >> n;
  21.     } while (n < 0);
  22.    
  23.     *p = n; //despues de validar n
  24.  
  25.     for (int i = 1; i <= *p; i++)
  26.     {
  27.         factorial = factorial*i;
  28.     }
  29.  
  30.     delete p;
  31.     cout << factorial << endl;
  32. }
  33. void Fexponencial()
  34. {
  35.     int a, k;
  36.     float resultado = 1; // porque tiene un 1 al inicio
  37.     float factorial = 1; // porque no existe division entre 0  
  38.    
  39.     int *pk, *pa;
  40.  
  41.     pk = new int;
  42.     pa = new int;
  43.  
  44.     do
  45.     {
  46.         cout << "Ingrese un numero a positivo: "; cin >> a;
  47.     } while (a < 0);
  48.  
  49.     *pk = k;
  50.  
  51.     do
  52.     {
  53.         cout << "Ingrese un numero k positivo: "; cin >> k;
  54.     } while (k < 0);
  55.  
  56.     *pa = a;
  57.  
  58.     for (int i = 1; i <= k; i++)
  59.     {
  60.         factorial = factorial*i;
  61.         resultado = resultado + (pow(a, i)) / factorial;
  62.     }
  63.  
  64.     cout << resultado << endl;
  65. }
  66. void dibuja()
  67. {
  68.     int N;
  69.     int *pn;
  70.     pn = new int;
  71.  
  72.     do{
  73.         cout << "Ingrese N: " << endl;
  74.         cin >> N;
  75.     } while (N<0 || N>11);
  76.  
  77.     *pn = N;
  78.     for (int linea = 1; linea <= N; linea++){
  79.  
  80.         for (int e = 1; e <= N - linea; e++)
  81.             cout << "  ";
  82.  
  83.         int Numero_maximo = 2 * linea - 1;
  84.  
  85.         for (int Numeros = 1; Numeros <= Numero_maximo; Numeros++)
  86.             cout << Numeros << " ";
  87.  
  88.         cout << endl;
  89.     }
  90.  
  91.     int Numero_maximo = 2 * (N - 1) - 1;
  92.  
  93.     for (int linea = N + 1; linea <= 2 * N - 1; linea++){
  94.    
  95.         for (int e = 1; e <= linea - N; e++)
  96.             cout << "  ";
  97.    
  98.         for (int Numeros = 1; Numeros <= Numero_maximo; Numeros++)
  99.             cout << Numeros << " ";
  100.         cout << endl;
  101.         Numero_maximo -= 2;
  102.     }
  103. }
  104. void menu()
  105. {
  106.     cout << "\t\t MENU PRINCIPAL" << endl;
  107.     cout << " 1) Determinar el factorial de un numero" << endl;
  108.     cout << " 2) Calcula el valor de e^a" << endl;
  109.     cout << " 3) Imprime rombo" << endl;
  110.     cout << " 4) Fin" << endl;
  111. }
  112. void main()
  113. {
  114.     int n, k, a, opcion, N;
  115.    
  116.  
  117.     while (1)
  118.     {
  119.         menu();
  120.         cout << "Elija la opcion: "; cin >> opcion;
  121.         switch (opcion)
  122.         {
  123.         case 1:
  124.             Ffactorial() ;
  125.             break;
  126.         case 2:
  127.             Fexponencial();
  128.             break;
  129.         case 3:
  130.             dibuja();
  131.             break;
  132.         case 4:
  133.             exit(0);
  134.             break;
  135.         default:
  136.             cout << "Error de opcion" << endl;
  137.         }
  138.         _getch();
  139.         system("cls");
  140.     }
  141.     getch();
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement