Home > Back-end >  Bosses look at why? Please help sinx wrong results
Bosses look at why? Please help sinx wrong results

Time:04-02

#include
using namespace std;

Double fac (int num1) {
Int resualt1=1;

While (num1 & gt;
=1){
Resualt1 *=num1;
Num1 -;
}
Return resualt1;
}

Double power (int num2, int num3) {
Int resualt2=1;

While (num3 & gt;
=1){
Resualt2 *=num2;
Num3 -;
}
Return resualt2;
}

Double sin1 (double x) {
Double SQR=x * x;
Double e=x;
Double r=0;
int i=1;

While (I & lt; 13)={
Double f=e/fac (I);

R=(I % 4==1)? R + f: r - f;
E=e * SQR.
I +=2;
}
return r;
}

Int main () {
Cout & lt; & lt; Sin1 (5) & lt; & lt; Endl;

return 0;
}

CodePudding user response:

Factorial function double fac (int num1), int resualt1=1; Data type is wrong, the result error is a bit, for reference:
 # include & lt; Iostream> 
#include
using namespace std;

Double fac (int num1) {
Double resualt1=1.0;
//int resualt1=1; 13!=6227020800 int 32 bits, the maximum value is: 2147483647
While (num1 & gt;
=1){
Resualt1 *=num1;
Num1 -;
}
Return resualt1;
}

Double power (int num2, int num3) {
Int resualt2=1;

While (num3 & gt;
=1){
Resualt2 *=num2;
Num3 -;
}
Return resualt2;
}

Double sin1 (double x) {
Double SQR=x * x;
Double e=x;
Double r=0;
int i=1;
Double f;

While (I & lt; 13)={
F=e/fac (I);

R=(I % 4==1)? R + f: r - f;

E=e * SQR.

I +=2;
}
return r;
}

Int main () {
Cout & lt; & lt; Sin1 (5) & lt; & lt; Endl;
system("pause");
return 0;
}

//0.937584
//please press any key to continue...




CodePudding user response:

reference 1st floor QZJHJXJ response:
factorial function double fac (int num1), int resualt1=1; Data type is wrong, the result error is a bit, for reference:
 # include & lt; Iostream> 
#include
using namespace std;

Double fac (int num1) {
Double resualt1=1.0;
//int resualt1=1; 13!=6227020800 int 32 bits, the maximum value is: 2147483647
While (num1 & gt;
=1){
Resualt1 *=num1;
Num1 -;
}
Return resualt1;
}

Double power (int num2, int num3) {
Int resualt2=1;

While (num3 & gt;
=1){
Resualt2 *=num2;
Num3 -;
}
Return resualt2;
}

Double sin1 (double x) {
Double SQR=x * x;
Double e=x;
Double r=0;
int i=1;
Double f;

While (I & lt; 13)={
F=e/fac (I);

R=(I % 4==1)? R + f: r - f;

E=e * SQR.

I +=2;
}
return r;
}

Int main () {
Cout & lt; & lt; Sin1 (5) & lt; & lt; Endl;
system("pause");
return 0;
}

//0.937584
//please press any key to continue...

Tried, no problem, thank you for your bosses
  • Related