c - 我如何根据斐波那契方法编写 ipo 图表?

标签 c fibonacci pseudocode

这是我根据斐波那契方法编写的内容,但当归结为围绕它绘制 IPO 图表时,我似乎陷入了处理阶段。我知道这应该很容易做到,但我对此还比较陌生。

这是另一个 IPO 图表的示例:

enter image description here

#include<stdio.h>
#include<string.h>
main()
{
  int n,t=0,tt=1,b=0,i;
  printf("Enter sequence limit: ");
  scanf("%d",&n);
  printf("Fibonacci sequence: %d %d",t,tt);
  b=t+tt;
  for (i=1;b<=n;i++)
  {
    printf(" %d ",b);
    t=tt;
    tt=b;
    b=t+tt;
  }
return 0;
}

最佳答案

循环条件不正确:

for (i=1;b<=n;i++)

你需要i<=n不是b<=n ,因为你需要 n序号。

#include<stdio.h>
#include<string.h>
int main(void)
{
  int n,t=0,tt=1,b=0,i;

  printf("Enter sequence limit: ");
  scanf("%d",&n);

  printf("Fibonacci sequence: %d %d\n",t,tt);

  b=t+tt;
  for (i=1; i<=n; i++)
  {
    printf(" %d ",b);
    t=tt;
    tt=b;
    b=t+tt;
  }
return 0;
}

输出:

Enter sequence limit: 10                                                                                                                     
Fibonacci sequence: 0 1                                                                                                                      
 1  2  3  5  8  13  21  34  55  89

根据有关IPO的新信息:

#include<stdio.h>

int main(void){
    float weekly_pay;
    float raise;
    float weekly_raise;
    float new_weekly_pay;

    // 1. current weekly pay:
    printf("Enter weekly_pay: \n");
    scanf("%f",&weekly_pay);

    // 2. raise rate
    printf("Enter raise: \n");
    scanf("%f",&raise);

    // 3. weekly raise
    weekly_raise = weekly_pay * raise;

    // 4.new weekly pay
    new_weekly_pay = weekly_pay + weekly_raise;

    // 5. Output:
    printf("New weekly pay is: %8.2f \n", new_weekly_pay);

    return 0;
}

输入:

100.0
0.01

输出:

New weekly pay is:   101.00 

关于c - 我如何根据斐波那契方法编写 ipo 图表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49068356/

相关文章:

java - 递归打印斐波那契数列

string - 遍历并索引文本文件

c++ - 字符串字母的排列 : How to remove repeated permutations?

c - 使用 pthreads 添加两个 vector 而不使用全局 sum 变量

java - 在 Java 中使用 BigInteger 的递归斐波那契数列

algorithm - 这个算法有什么作用?

运行大型倒数计时器的代码

c - 如何处理别人的驱动程序的内存泄漏

c++ - 函数 int86 编译错误 : "Stray 302",

c - 在 C 中使用共享内存的斐波那契数列