#include #include #include int substr(char dst[], char src[], int start, int len
程序员文章站
2022-09-28 15:36:42
#include
#include
double print_s(int a)
{
double p1[5...
#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; }