Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- using namespace System;
- using namespace std;
- void Menu(){
- cout << " Menu de opcion"<<endl;
- cout << "1. Calcular el seno"<<endl;
- cout << "2. Hallar el enesimo digito" << endl;
- cout << "3. Fin" << endl;
- cout << "Ingrese opcion: ";
- }
- void Ingresar_N(int *N){
- do
- {
- cout << "Ingrese el valor de N:";
- cin >> *N;
- } while (*N<0);
- }
- void Ingresar_x(int *x){
- do
- {
- cout << "Ingrese el valor de X:";
- cin >> *x;
- } while (*x<0);
- }
- void Factorial(int *fact, int i){
- *fact = 1;
- for (int j = 0; j < (i * 2) + 1; j++)
- {
- if (j == 0)
- {
- *fact = 1;
- }
- else
- *fact = *fact + j;
- }
- }
- void SenX(int *N){
- int *x = new int;
- Ingresar_x(x);
- int *fact = new int;
- double *suma = new double;
- *suma = 0;
- for (int i = 0; i < *N; i++)
- {
- Factorial(fact, i);
- *suma = *suma + pow(-1, i)*(pow(*x, 2 * i + 1) / *fact);
- }
- cout << "El seno de " << *x << " es: " << *suma<<endl;
- }
- void Ingresar_num(int *num){
- do
- {
- cout << "Ingrese el numero: ";
- cin >> *num;
- } while (*num<0);
- }
- void Digit(int *N,int *num){
- int n1, n2;
- int numero;
- n1 = pow(10, *N + 1);
- n2 = pow(10, *N);
- numero = ((*num % n1) - (*num % n2)) / n2;
- if (numero < 0)
- numero = numero * (-1);
- if (numero != 0){
- cout << "El n-esimo digito es: " << numero << endl;
- }else
- cout << "El n-esimo digito es : -1" << endl;
- }
- int main(array<System::String ^> ^args)
- {
- int opc_menu;
- int *N = new int;
- int *num = new int;
- while (1)
- {
- cout << "----------------------------------------------------" << endl;
- Menu();
- cin >> opc_menu;
- switch (opc_menu)
- {
- case 1:
- Ingresar_N(N);
- SenX(N);
- break;
- case 2:
- Ingresar_N(N);
- Ingresar_num(num);
- Digit(N,num);
- break;
- case 3:
- exit(0);
- break;
- default:
- break;
- }
- }
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement