计算2/1+3/2+5/3+8/5+13/8...
输入项数,得到计算结果
#include<stdio.h> #include<stdlib.h> int main() { double num = 0;//分子 double deno = 0;//分母 int i = 0; int count ; double sum = 0; double tmp = 1; sum = 0; num = 2; deno = 1; printf("请输入项数:\n"); scanf("%d", &count); for (i = 1; i <= count; i++) { sum = sum+num / deno; num = num + deno; tmp = deno; deno = tmp + deno; } printf("sum=%f", sum); system("pause"); return 0; }