Advertisement
pcsiasop

ej1

May 25th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int factorial(int num);
  4. double funcionSeno1(int x, int n);
  5. void main()
  6. {
  7.     int x;
  8.     int num = 10;
  9.     int opcion;
  10.     bool salir = false;
  11.     do
  12.     {
  13.         cout << "1 Calculo del seno: "<<endl;
  14.         cout << "2 Digito: "<<endl;
  15.         cout << "3 Digito: "<<endl;
  16.         cin >> opcion; 
  17.         switch (opcion)
  18.         {
  19.         case 1:
  20.             cout << "Valor de x: ";
  21.             cin >> x;
  22.             cout << "El seno de x es: " << funcionSeno1(x, num)<<endl;
  23.             break;
  24.         case 2:
  25.  
  26.         case 3:
  27.         salir = true;
  28.         break;
  29.            
  30.         }
  31.     }
  32.     while (salir==false);
  33.  
  34.  
  35.     system("pause");
  36. }
  37. double funcionSeno1(int x, int n)
  38. {
  39.     double seno=0;
  40.  
  41.     for (int i = 0; i <=n; i=i+1)
  42.     {
  43.         seno = seno + (double)pow(-1, i)*pow(x, 2 * i + 1) / factorial(2 * i + 1);
  44.     }
  45.  
  46.     return seno;
  47. }
  48. int factorial(int num)
  49. {
  50.     int fac = 1;
  51.     if (num == 0 || num == 1) fac = 1;
  52.     for (int i = 1; i <=num; i++)
  53.     {
  54.         fac = fac*i;
  55.     }
  56.     return fac;
  57. }
  58.  
  59. int digito(int p, int num)
  60. {
  61.     int digito;
  62.     int contador=0;
  63.     num = abs(num);
  64.     do {
  65.         digito = num%10;
  66.         num = num / 10;
  67.    
  68.         contador++;
  69.         if (p+1 == contador)
  70.            
  71.             break;
  72.     } while (num>0);
  73.  
  74.     if (p+1>contador) digito = -1;
  75.     return digito;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement