Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <iomanip>
- using namespace std;
- long double seno(long double x,int y);
- long double coseno(long double x,int y);
- long double senoh(long double x,int y);
- long double cosenoh(long double x,int y);
- long long int factorial(int b);
- int i,j;
- main (){
- double x,y;
- int opc;
- cout<<"Ingrese el valor de z: "<<endl;
- cin>>x;
- cout<<"Ingrese cuantos terminos desea en la serie (a)\n Recomandado usar un valor menor a 10: "<<endl;
- cin>>y;
- system("cls");
- cout<<"1. Seno("<<x<<")\n2. Coseno("<<x<<")\n3. Senoh("<<x<<")\n4. Cosenoh("<<x<<")\nIngrese una Opcion: "<<endl;
- cin>>opc;
- cout<<fixed<<setprecision(7);
- switch (opc){
- case 1:
- cout<<"seno = "<<seno(x,y)<<endl;
- break;
- case 2:
- cout<<"coseno = "<<coseno(x,y)<<endl;
- break;
- case 3:
- cout<<"senoh = "<<senoh(x,y)<<endl;
- break;
- case 4:
- cout<<"cosenoh = "<<cosenoh(x,y)<<endl;
- break;
- }
- }
- long double seno (long double x, int y){
- double acum=0;
- for (i=0;i<=(y+1);i++){
- acum=acum+pow(-1,i)*(pow(x,(2*i+1))/factorial(2*i+1));
- }
- return acum;
- }
- long double coseno(long double x,int y){
- double acum=0;
- for (i=0;i<=(y+1);i++){
- acum=acum+pow(-1,i)*(pow(x,(2*i))/factorial(2*i));
- }
- return acum;
- }
- long double senoh(long double x,int y){
- double acum=0;
- for (i=0;i<=(y+1);i++){
- acum=acum+(pow(x,(2*i+1))/factorial(2*i+1));
- }
- return acum;
- }
- long double cosenoh(long double x,int y){
- double acum=0;
- for (i=0;i<=(y+1);i++){
- acum=acum+(pow(x,(2*i))/factorial(2*i));
- }
- return acum;
- }
- long long int factorial(int b){
- long long int acum2=1;
- for (j=0;j<=b;j++){
- if (j==0){
- acum2=1;
- }else {
- acum2=acum2*j;
- }
- }
- return acum2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement