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

问题描述 投票:1回答:1

这是我根据Fibonacci方法编写的内容,但当它围绕它做一个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;
}
c fibonacci pseudocode
1个回答
1
投票

循环中的条件不正确:

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 
© www.soinside.com 2019 - 2024. All rights reserved.