Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- using namespace System;
- void menu()
- {
- cout << "Menu de opciones\n\n";
- cout << "1.Determinar el factorial de un numero\n";
- cout << "2.Calcular el valor de e^a\n";
- cout << "3.Imprime rombo\n";
- cout << "4.Fin\n";
- }
- float factorial(int n)
- {
- float fact = 1;
- int c;
- for (c = 1;c <= n;c++)
- fact = fact*c;
- return fact;
- }
- float exponencial(float a, int k)
- {
- float suma = 0;
- for (int c = 0;c <= k;c++)
- suma = suma + pow(a, c) / factorial(c);
- return suma;
- }
- void dibuja(int n)
- {
- int fila, c, blancos;
- for (fila = 1;fila <= n;fila++)
- {
- blancos = n - fila;
- for (c = 1;c <= blancos;c++)
- cout << " ";
- for (c = 1;c <= 2 * fila-1;c++)
- cout << c;
- cout << endl;
- }
- for (fila = n - 1;fila >= 1;fila--)
- {
- blancos = n - fila;
- for (c = 1;c <= blancos;c++)
- cout << " ";
- for (c = 1;c <= 2 * fila - 1;c++)
- cout << c;
- cout << endl;
- }
- }
- void main()
- {
- int n, k, opcion;
- float a;
- do
- {
- Console::Clear();
- menu();
- do
- {
- cout << "Ingrese su opcion:";cin >> opcion;
- }while(opcion<1||opcion>4);
- if (opcion != 4)
- {
- Console::Clear();
- switch (opcion)
- {
- case 1:cout << "Calculo del factorial\n";
- do
- {
- cout << "Ingrese el valor de N:";
- } while (n < 0);
- cout << "Facotorial=" << factorial(n) << endl;
- break;
- case 2:cout << "Calculo del exponencial\n";
- cout << "Ingrese el valor de a\n";cin >> a;
- do
- {
- cout << "Ingrese el valor de k\n";cin >> k;
- } while (k<0||k>20);
- cout << "Exponencial=" << exponencial(a, k) << endl;
- break;
- case 3:cout << "Dibujo del Rombo\n";
- do
- {
- cout << "Ingrese el valor de N\n";cin >> n;
- } while (n<1||n>10);
- dibuja(n);
- cout << endl;
- }
- cout << "Presione una tecla para continuar";
- _getch();
- }
- } while (opcion != 4);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement