{
  "question_id": 7446208,
  "question_title": "求数列第n项值",
  "question_content": "<p>求数列第n项值&#xff1a;1,2,3,6,11,20,37,68,125,230,.....例如:第7项为37&#xff0c;第9项为125。</p>",
  "difficulty": "简单",
  "answer_id": 53425424,
  "answer_content": "<pre>\n<code class=\"language-cpp\">#include &lt;stdio.h&gt;\n\nint main(void) { \n    int n;\n    printf(&#34;请输入n的值&#xff1a;&#34;);\n    scanf(&#34;%d&#34;,&amp;n);\n    if(n&#61;&#61;1){\n        printf(&#34;第1项为1\\n&#34;);\n    }else if(n&#61;&#61;2){\n        printf(&#34;第2项为2\\n&#34;);\n    }else if(n&#61;&#61;3){\n        printf(&#34;第3项为3\\n&#34;);\n    }else{\n        int f1&#61;1,f2&#61;2,f3&#61;3;\n        int i,fn;\n        for(i&#61;4;i&lt;&#61;n;i&#43;&#43;){\n            fn&#61;f1&#43;f2&#43;f3;\n            f1&#61;f2;\n            f2&#61;f3;\n            f3&#61;fn;\n        }\n        printf(&#34;第%d项为%d\\n&#34;,n,fn);\n    }\n    return 0;\n}</code></pre>\n\n<p> </p>\n",
  "tag_name": "c++",
  "cpp": "#include <stdio.h>\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,
  "author": "xushao180"
}