AbsoluteZero
09-10-2003, 03:07 PM
Hi can anyone help me using the factorial function?
Heres the code:
#include <iostream.h>
#include <math.h>
int main() {
double sen;
double sen2;
int elemento=1;
double x;
long double fnction;
int z=3;
int resultado;
int factorial(int n)
x=0.523598;
sen = sin(0.523598);
cout<<"El seno de 30 grados es "<<sen<<endl;
sen2=0.5235969;
resultado=sen-sen2;
while (resultado>0.000001) {
fnction=-(pow(x,z))/(factorial(z));
sen2=30+fnction;
elemento++;
z+=2;
fnction=-fnction;
}
cout<<"Se requieren "<<elemento-1<<" elemento(s)"<<endl;
}
im trying to get an error of less than 0.000001 for the sine function. I have to determine the number of elements needed to do this. I think theres an error in how im using the factorial function. Thanks
Heres the code:
#include <iostream.h>
#include <math.h>
int main() {
double sen;
double sen2;
int elemento=1;
double x;
long double fnction;
int z=3;
int resultado;
int factorial(int n)
x=0.523598;
sen = sin(0.523598);
cout<<"El seno de 30 grados es "<<sen<<endl;
sen2=0.5235969;
resultado=sen-sen2;
while (resultado>0.000001) {
fnction=-(pow(x,z))/(factorial(z));
sen2=30+fnction;
elemento++;
z+=2;
fnction=-fnction;
}
cout<<"Se requieren "<<elemento-1<<" elemento(s)"<<endl;
}
im trying to get an error of less than 0.000001 for the sine function. I have to determine the number of elements needed to do this. I think theres an error in how im using the factorial function. Thanks