这是我根据Fibonacci方法编写的内容,但当它围绕它做一个IPO图表时,我似乎陷入了处理阶段。我知道这可能是容易做到的事情,但我对此比较陌生。
这是另一个IPO图表的示例:
#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;
}
答案 0 :(得分: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
根据有关首次公开招股的新资料:
#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