{ "question_id": 7446208, "question_title": "求数列第n项值", "question_content": "

求数列第n项值:1,2,3,6,11,20,37,68,125,230,.....例如:第7项为37,第9项为125。

", "difficulty": "简单", "answer_id": 53425424, "answer_content": "
\n#include <stdio.h>\n\nint main(void) { \n    int n;\n    printf("请输入n的值:");\n    scanf("%d",&n);\n    if(n==1){\n        printf("第1项为1\\n");\n    }else if(n==2){\n        printf("第2项为2\\n");\n    }else if(n==3){\n        printf("第3项为3\\n");\n    }else{\n        int f1=1,f2=2,f3=3;\n        int i,fn;\n        for(i=4;i<=n;i++){\n            fn=f1+f2+f3;\n            f1=f2;\n            f2=f3;\n            f3=fn;\n        }\n        printf("第%d项为%d\\n",n,fn);\n    }\n    return 0;\n}
\n\n

 

\n", "tag_name": "c++", "cpp": "#include \nint main(void) { \n\tint n;\n\tprintf(\"请输入n的值:\");\n\tscanf(\"%d\",&n);\n\tif(n==1){\n\t\tprintf(\"第1项为1\\n\");\n\t}else if(n==2){\n\t\tprintf(\"第2项为2\\n\");\n\t}else if(n==3){\n\t\tprintf(\"第3项为3\\n\");\n\t}else{\n\t\tint f1=1,f2=2,f3=3;\n\t\tint i,fn;\n\t\tfor(i=4;i<=n;i++){\n\t\t\tfn=f1+f2+f3;\n\t\t\tf1=f2;\n\t\t\tf2=f3;\n\t\t\tf3=fn;\n\t\t}\n\t\tprintf(\"第%d项为%d\\n\",n,fn);\n\t}\n\treturn 0;\n}", "topic_link": "https://bbs.csdn.net/topics/600469855", "status": 1, "keywords": "数列,数学运算", "license": "csdn.net", "notebook": { "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/85.ipynb?type=file" }, "notebook_enable": 1 }