{ "type": "code_options", "author": "csdn.net", "source": "solution.md", "exercise_id": "d421a78bd062493383fff7b3dbb32b05", "keywords": "递归,数学运算", "title": "求数列的第n项的值", "desc": [ { "content": "\n已知数列:2,4,4,4,6,6,6,6,6,8,8,8,8,8,8,8,...求第n项的值", "language": "markdown" } ], "answer": [ { "content": "", "language": "cpp" } ], "prepared": [ [ { "content": "", "language": "cpp" } ], [ { "content": "", "language": "cpp" } ], [ { "content": "", "language": "cpp" } ] ], "template": { "content": "#include \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}", "language": "cpp" }, "node_id": "dailycode-a530e610620e44b4b389ef63e0b238cc", "license": "csdn.net", "created_at": 1637894160, "topic_link": "https://bbs.csdn.net/topics/600470260" }