Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace System;
- using std::cout;
- using std::cin;
- using std::endl;
- short menu() {
- short *opcion = new short;
- do {
- cout << "1-Determinar el factorial de un numero : " << endl;
- cout << "2-Calcular de e^a : " << endl;
- cout << "3-Imprimir Rombo : " << endl;
- cout << "4-Salir : " << endl;
- cin >> *opcion;
- } while (*opcion < 1 || *opcion>4);
- return *opcion;
- }
- long factorial(short *nro) {
- short c = 1;
- long factorial(1);
- do {
- factorial *= c;
- ++c;
- } while (c <= *nro);
- return factorial;
- }
- long potencia(short *b, short *exp) {
- long r = 1;
- for (int c = 1; c <= *exp; ++c)
- {
- r *= *b;
- }
- return r;
- }
- void sumatoria(short *a, short *k){
- float r = 1;
- for (short c = 1; c <= *k; ++c)
- r += (float)potencia(a, &c) / (float)factorial(&c);
- cout << r;
- }
- void graficar(int l) {
- for (short cf = 1; cf<= l; cf++)
- {Console::SetCursorPosition(40-cf-1, cf);
- for (short cc = 1; cc <= 2*cf-1; cc++)
- {
- cout << cc;
- }
- cout<<endl;
- }
- //////
- for (short cf = 1; cf <= l; cf++)
- {
- Console::SetCursorPosition(40 - cf-1 , 2*l-cf);
- for (short cc = 1; cc <= 2 * cf - 1; cc++)
- {
- cout << cc;
- }
- cout << endl;
- }
- }
- short ingresarNro() {
- short nro;
- do{
- cout << "ingrese nro : ";
- cin >> nro;
- } while (nro < 0 || nro>10);
- return nro;
- }
- int main() {
- short op = menu();
- short *nro = new short;
- short *a = new short;
- short *k = new short;
- float *suma;
- switch (op) {
- case 1:
- *nro=ingresarNro();
- cout << "El factorial es : " << factorial(nro);break;
- case 2:
- *a = ingresarNro();
- *k = ingresarNro();
- sumatoria(a, k);break;
- case 3:
- *nro = ingresarNro();
- graficar(*nro);
- default:;
- }
- cin.ignore();
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement