{
"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 <iostream>\n\nint main()\n{\n unsigned int N;\n std::cout << "Please enter the value of N: ";\n std::cin >> N;\n if (N % 2 != 0)\n {\n std::cout << "Please enter an even number greater than zero!" << std::endl;\n return -1;\n }\n\n int oddCount = 1;\n int printCount = 0;\n for (int i = 2; i <= N; i += 2)\n {\n for (int j = 0; j < oddCount; j++)\n {\n std::cout << i << " ";\n printCount++;\n if (printCount == N)\n {\n std::cout << "<---这个就是第N = " << N << "个数。" << std::endl;\n return 0;\n }\n }\n\n oddCount += 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"
}