我不知道为什么我将最后一个数字视为否定。
我希望输出为0 1 1 ...'n'数字(斐波纳契系列)
int x, y, avoid;
System.out.println("Enter x: ");
x = System.in.read();
// Reading all the characters after the first character so that
// no character stays pending in the input buffer.
do {
avoid = System.in.read();
} while(avoid != '\n');
System.out.println("Enter y: ");
// New input buffer is created.
y = System.in.read();
do {
avoid = System.in.read();
} while(avoid != '\n');
答案 0 :(得分:2)
是的,它肯定超出了int范围
1836311903 //before last
-1323752223 //last
max int是2,147,483,647
如果你想要超过n = 48,你必须声明a,b,c为长型
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
long a=-1,b=1,c=0;
for(int i=0;i<n;i++)
{
c=a+b;
printf("%ld\n",c);
a=b;
b=c;
}
return 0;
}