Advertisement
Guest User

Hoja 03- Ejercicio 1

a guest
Oct 24th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <conio.h>
  4. using namespace System;
  5. using namespace std;
  6. void Menu(){
  7. cout << " Menu de opcion"<<endl;
  8. cout << "1. Calcular el seno"<<endl;
  9. cout << "2. Hallar el enesimo digito" << endl;
  10. cout << "3. Fin" << endl;
  11. cout << "Ingrese opcion: ";
  12. }
  13. void Ingresar_N(int *N){
  14. do
  15. {
  16. cout << "Ingrese el valor de N:";
  17. cin >> *N;
  18. } while (*N<0);
  19. }
  20. void Ingresar_x(int *x){
  21. do
  22. {
  23. cout << "Ingrese el valor de X:";
  24. cin >> *x;
  25. } while (*x<0);
  26. }
  27. void Factorial(int *fact, int i){
  28. *fact = 1;
  29. for (int j = 0; j < (i * 2) + 1; j++)
  30. {
  31. if (j == 0)
  32. {
  33. *fact = 1;
  34. }
  35. else
  36. *fact = *fact + j;
  37. }
  38. }
  39. void SenX(int *N){
  40. int *x = new int;
  41. Ingresar_x(x);
  42. int *fact = new int;
  43. double *suma = new double;
  44. *suma = 0;
  45. for (int i = 0; i < *N; i++)
  46. {
  47. Factorial(fact, i);
  48. *suma = *suma + pow(-1, i)*(pow(*x, 2 * i + 1) / *fact);
  49. }
  50. cout << "El seno de " << *x << " es: " << *suma<<endl;
  51.  
  52. }
  53. void Ingresar_num(int *num){
  54. do
  55. {
  56. cout << "Ingrese el numero: ";
  57. cin >> *num;
  58. } while (*num<0);
  59. }
  60. void Digit(int *N,int *num){
  61.  
  62. int n1, n2;
  63. int numero;
  64. n1 = pow(10, *N + 1);
  65. n2 = pow(10, *N);
  66. numero = ((*num % n1) - (*num % n2)) / n2;
  67. if (numero < 0)
  68. numero = numero * (-1);
  69.  
  70. if (numero != 0){
  71. cout << "El n-esimo digito es: " << numero << endl;
  72. }else
  73. cout << "El n-esimo digito es : -1" << endl;
  74. }
  75. int main(array<System::String ^> ^args)
  76. {
  77. int opc_menu;
  78. int *N = new int;
  79. int *num = new int;
  80. while (1)
  81. {
  82. cout << "----------------------------------------------------" << endl;
  83. Menu();
  84. cin >> opc_menu;
  85. switch (opc_menu)
  86. {
  87. case 1:
  88. Ingresar_N(N);
  89. SenX(N);
  90. break;
  91. case 2:
  92. Ingresar_N(N);
  93. Ingresar_num(num);
  94. Digit(N,num);
  95. break;
  96. case 3:
  97. exit(0);
  98. break;
  99. default:
  100. break;
  101. }
  102. }
  103. _getch();
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement