solution.json 1.4 KB
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "a9b93d1decbc46a0b40aa01f35b02ea3",
  "keywords": "循环",
  "title": "不同方式求n的阶乘",
  "desc": [
    {
      "content": "\n<p>求n的阶乘&#xff08;用三种不同的循环实现&#xff0c;提示&#xff1a;先从键盘输入n的值&#xff09;while、do while和for</p>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include <stdio.h>\nint main(void) { \n\tint n;\n\tprintf(\"请输入n的值:\");\n\tscanf(\"%d\",&n);\n\tint temp=n,sum=1;\n\twhile(temp>1){\n\t\tsum*=temp;\n\t\ttemp--;\n\t}\n\tprintf(\"%d的阶乘是%d\\n\",n,sum);\n\ttemp=n;\n\tsum=1;\n\tdo{\n\t\tsum*=temp;\n\t\ttemp--;\n\t}while(temp>1);\n\tprintf(\"%d的阶乘是%d\\n\",n,sum);\n\ttemp=n;\n\tsum=1;\n\tfor(;temp>1;temp--){\n\t\tsum*=temp;;\n\t}\n\tprintf(\"%d的阶乘是%d\\n\",n,sum);\n\treturn 0;\n}",
    "language": "cpp"
  },
  "node_id": "dailycode-50a57ff04dbd44e19752bef441bb988b",
  "license": "csdn.net",
  "created_at": 1637894160,
  "topic_link": "https://bbs.csdn.net/topics/600469955"
}