52.json 2.3 KB
Newer Older
每日一练社区's avatar
test  
每日一练社区 已提交
1
{
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
  "question_id": 7445111,
  "question_title": "求数列的第n项的值",
  "question_content": "已知数列:2,4,4,4,6,6,6,6,6,8,8,8,8,8,8,8,...求第n项的值",
  "difficulty": "简单",
  "answer_id": 53424084,
  "answer_content": "<p style=\"text-align:center\"><img alt=\"\" src=\"https://img-ask.csdnimg.cn/upload/1623205203176.png\" /></p>\n\n<pre>\n<code class=\"language-cpp\">#include &lt;iostream&gt;\n\nint main()\n{\n    unsigned int N;\n    std::cout &lt;&lt; &#34;Please enter the value of N: &#34;;\n    std::cin &gt;&gt; N;\n    if (N % 2 !&#61; 0)\n    {\n        std::cout &lt;&lt; &#34;Please enter an even number greater than zero!&#34; &lt;&lt; std::endl;\n        return -1;\n    }\n\n    int oddCount &#61; 1;\n    int printCount &#61; 0;\n    for (int i &#61; 2; i &lt;&#61; N; i &#43;&#61; 2)\n    {\n        for (int j &#61; 0; j &lt; oddCount; j&#43;&#43;)\n        {\n            std::cout &lt;&lt; i &lt;&lt; &#34; &#34;;\n            printCount&#43;&#43;;\n            if (printCount &#61;&#61; N)\n            {\n                std::cout &lt;&lt; &#34;&lt;---这个就是第N &#61; &#34; &lt;&lt; N &lt;&lt; &#34;个数。&#34; &lt;&lt; std::endl;\n                return 0;\n            }\n        }\n\n        oddCount &#43;&#61; 2;\n    }\n    return 0;\n}\n</code></pre>\n\n<p> </p>\n",
  "tag_name": "c语言",
  "cpp": "#include <iostream>\nint main()\n{\n\tunsigned int N;\n\tstd::cout << \"Please enter the value of N: \";\n\tstd::cin >> N;\n\tif (N % 2 != 0)\n\t{\n\t\tstd::cout << \"Please enter an even number greater than zero!\" << std::endl;\n\t\treturn -1;\n\t}\n\tint oddCount = 1;\n\tint printCount = 0;\n\tfor (int i = 2; i <= N; i += 2)\n\t{\n\t\tfor (int j = 0; j < oddCount; j++)\n\t\t{\n\t\t\tstd::cout << i << \" \";\n\t\t\tprintCount++;\n\t\t\tif (printCount == N)\n\t\t\t{\n\t\t\t\tstd::cout << \"<---这个就是第N = \" << N << \"个数。\" << std::endl;\n\t\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\t\toddCount += 2;\n\t}\n\treturn 0;\n}",
  "topic_link": "https://bbs.csdn.net/topics/600470260",
  "status": 1,
  "keywords": "递归,数学运算",
  "license": "csdn.net",
  "notebook": {
    "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/52.ipynb?type=file"
  },
  "notebook_enable": 1,
  "author": "qq_45777679"
每日一练社区's avatar
test  
每日一练社区 已提交
19
}