Hey guys can you please check out my code why it is not working

actually one of the three testcase is not passing
I have given you the code please help and find whether the code is problem or testcase was wrong
#include
#include

using namespace std;

int main()
{
int a = 0 , b = 1 , c = a+b , n;
cin>>n;
if(n>0){
cout<<a<<endl;
cout<<b<<" “<<c<<endl;
a = b;
b = c;
c = a + b;
for(int i = 2 ; i < n ; ++i){
for(int j = 0 ; j <= i ;++j){
cout<<c<<” ";
a = b;
b = c;
c = a + b;
}
cout<<endl;
}
}
return 0;
}

Hi @Deepak388
First of all you should use long long int instead of int as Fibonacci series grows extremely fast and exceeds the range of int very quickly.
Secondly your code fails for the simplest testcase :
Input - 1
Expected Output :
0
Your Output :
0
1 1

1 Like

#include
using namespace std;

int main(){
int n;
cin>>n;
long long int a=0,b=1,c=1;
cout<<a<<endl;
if(n>0){
cout<<b<<" “<<c<<endl;
for(int i=3;i<=n;++i){
for(int j=1;j<=i;++j){
a=b;
b=c;
c=a+b;
cout<<c<<” ";
}
cout<<endl;
}
}
return 0;
}

is it right
if it is test case 3 is not passing

@Deepak388
As I already mentioned in my previous reply , your code fails for this testcase

Input :
1
Expected Output :
0
Your Output :
0
1 1

Please make the required changes to pass this testcase.

1 Like

thanks @tarunluthra I have been missing these simple once thanks again for your help