{
  "question_id": 1057668,
  "question_title": "计算sin(x)",
  "question_content": "\n描述\n计算sin(x)=x-x^3/3!+x^5/5!-X^7/7!+......,直到最后一项的绝对值小于10-7时停止计算。其中-2Π<=x<=2Π，^表示次方，如x^3表示x的3次方。\n输入\n一个实数x，-2Π<=x<=2Π\n输出\nsin(x)的值\n输入样例 1 \n3.142\n输出样例 1\n-0.000407347",
  "difficulty": "中等",
  "answer_id": 1254771,
  "answer_content": "\n```\n#include<stdio.h>\n#include<math.h>\n\ndouble sin(double);\ndouble nResult(double,double);\n\nint main()\n{\n    double x=0;\n    scanf(\"%lf\",&x);\n    printf(\"sin(%lf)=%lf\\n\",x,sin(x));\n    return 0;\n}\n\ndouble sin(double x)\n{\n    //sin(x)=x-x^3/3!+x^5/5!-x^7/7!+……+(-1)(n^2n+1)/(2n+1)!+……\n    int i=0;\n    double result=0,n=0;\n    while( fabs( n=nResult(x,2*++i-1) ) > 0e-7 )//绝对值大于10^-7次方就循环\n        result+=(i%2==1)?n:-n;\n    return result;\n}\n\ndouble nResult(double x,double n)\n{\n    //(n^2n+1)/(2n+1)!也就是n/1*n/2*n/3*n/4*.....n/(2n+1)\n    return n==1?x:nResult(x,n-1)*x/n;\n}\n```",
  "tag_name": "c++",
  "cpp": "#include<stdio.h>\n#include<math.h>\ndouble sin(double);\ndouble nResult(double,double);\nint main()\n{\n\tdouble x=0;\n\tscanf(\"%lf\",&x);\n\tprintf(\"sin(%lf)=%lf\\n\",x,sin(x));\n\treturn 0;\n}\ndouble sin(double x)\n{\n\tint i=0;\n\tdouble result=0,n=0;\n\twhile( fabs( n=nResult(x,2*++i-1) ) > 0e-7 )\n\t\tresult+=(i%2==1)?n:-n;\n\treturn result;\n}\ndouble nResult(double x,double n)\n{\n\treturn n==1?x:nResult(x,n-1)*x/n;\n}",
  "topic_link": "https://bbs.csdn.net/topics/600470166",
  "status": 1,
  "keywords": "算法初阶,快速排序,快速排序的描述,排序和顺序统计量",
  "license": "csdn.net",
  "notebook": {
    "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/74.ipynb?type=file"
  },
  "notebook_enable": 1,
  "author": "qq_31182221"
}