Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <iomanip>
- using namespace std;
- void Ffactorial()
- {
- int n;
- int factorial = 1;
- int *p;
- p = new int;
- do
- {
- cout << "Ingrese un numero positivo: "; cin >> n;
- } while (n < 0);
- *p = n; //despues de validar n
- for (int i = 1; i <= *p; i++)
- {
- factorial = factorial*i;
- }
- delete p;
- cout << factorial << endl;
- }
- void Fexponencial()
- {
- int a, k;
- float resultado = 1; // porque tiene un 1 al inicio
- float factorial = 1; // porque no existe division entre 0
- int *pk, *pa;
- pk = new int;
- pa = new int;
- do
- {
- cout << "Ingrese un numero a positivo: "; cin >> a;
- } while (a < 0);
- *pk = k;
- do
- {
- cout << "Ingrese un numero k positivo: "; cin >> k;
- } while (k < 0);
- *pa = a;
- for (int i = 1; i <= k; i++)
- {
- factorial = factorial*i;
- resultado = resultado + (pow(a, i)) / factorial;
- }
- cout << resultado << endl;
- }
- void dibuja()
- {
- int N;
- int *pn;
- pn = new int;
- do{
- cout << "Ingrese N: " << endl;
- cin >> N;
- } while (N<0 || N>11);
- *pn = N;
- for (int linea = 1; linea <= N; linea++){
- for (int e = 1; e <= N - linea; e++)
- cout << " ";
- int Numero_maximo = 2 * linea - 1;
- for (int Numeros = 1; Numeros <= Numero_maximo; Numeros++)
- cout << Numeros << " ";
- cout << endl;
- }
- int Numero_maximo = 2 * (N - 1) - 1;
- for (int linea = N + 1; linea <= 2 * N - 1; linea++){
- for (int e = 1; e <= linea - N; e++)
- cout << " ";
- for (int Numeros = 1; Numeros <= Numero_maximo; Numeros++)
- cout << Numeros << " ";
- cout << endl;
- Numero_maximo -= 2;
- }
- }
- void menu()
- {
- cout << "\t\t MENU PRINCIPAL" << endl;
- cout << " 1) Determinar el factorial de un numero" << endl;
- cout << " 2) Calcula el valor de e^a" << endl;
- cout << " 3) Imprime rombo" << endl;
- cout << " 4) Fin" << endl;
- }
- void main()
- {
- int n, k, a, opcion, N;
- while (1)
- {
- menu();
- cout << "Elija la opcion: "; cin >> opcion;
- switch (opcion)
- {
- case 1:
- Ffactorial() ;
- break;
- case 2:
- Fexponencial();
- break;
- case 3:
- dibuja();
- break;
- case 4:
- exit(0);
- break;
- default:
- cout << "Error de opcion" << endl;
- }
- _getch();
- system("cls");
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement