有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前n项之和的整数部分c语言代码
时间: 2023-06-05 15:07:12 浏览: 71
C语言程序设计-求一分数序列21,32,53,85,138,2113…的前n项之和;说明:每一分数的分母是前两项的分母之
5星 · 资源好评率100%
int n, i;
double numerator, denominator, temp = 0;
scanf("%d", &n);
numerator = 2.0;
denominator = 1.0;
for (i = 1; i <= n; i++) {
temp += numerator / denominator;
numerator += denominator;
denominator = numerator - denominator;
}
printf("%d\n", (int)temp);
return 0;
阅读全文