solution.json 1.6 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": "07b64188801e410c82dbb0a4cfe65013",
  "keywords": "算法初阶,基础知识,特征序列,概率分析和随机算法,概率分析和指示器随机变量的进一步使用",
  "title": "求分数数列的前N项和",
  "desc": [
    {
      "content": "\n有一分数序列:2/1,-3/2,5/3,-8/5,13/8,-21/13,…, 由用户输入项目数N,求这个数列的前N 项之和",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "cpp"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ],
    [
      {
        "content": "",
        "language": "cpp"
      }
    ]
  ],
  "template": {
    "content": "#include<stdlib.h> \n#include<stdio.h>\nint main(){\n\tint n;\n\tscanf(\"%d\",&n);\n\tint i;\n\tdouble a1 = 2, b1 = 1;\n\tdouble a2 = 3, b2 = 2;\n\tdouble sum = a1/b1 - a2/b2;\n\tif(n==1) printf(\"%f\\n\",a1/b1);\n\telse if (n==2) printf(\"%f\\n\",sum);\n\telse{\n\t\tfor(i = 0;i<n-2;i++){\n\t\t\tdouble exp = a2 / b2;\n\t\t\tif(i%2==0) exp *= -1;\n\t\t\tsum += exp;\n\t\t\tdouble a = a1 + a2;\n\t\t\tdouble b = b1 + b2;\n\t\t\ta1 = a2;b1 = b2;\n\t\t\ta2 = a; b2 = b;\n\t\t}\n\t\tprintf(\"%f\\n\",sum);\n\t}\n\treturn 0;\n}",
    "language": "cpp"
  },
  "node_id": "dailycode-93ac67f3484a450782766cb42d60c7d9",
  "license": "csdn.net",
  "created_at": 1637894160,
  "topic_link": "https://bbs.csdn.net/topics/600470268"
}