#include<stdio.h> #include<stdlib.h> double print_s(int a) { double p1[50],p2[50],Sn[50]; int i = 0; p1[0] = 2; p2[0] = 1; Sn[0] = p1[0] / p2[0]; for (i = 1; i < a; i++) { p1[i] = p1[i - 1] + p2[i - 1]; p2[i] = p1[i] - p2[i - 1]; Sn[i] = Sn[i - 1] + (p1[i] / p2[i]); } return (Sn[a - 1]); } int main() { int a; printf("請輸入您要打印這個分數序列前幾項和:"); scanf("%d",&a); printf("本序列前%d項和Sn=%2.5f\n",a,print_s(a)); system("pause"); return 0; }