FIbbonacci pattern

#include

using namespace std;

int main()
{
int n,a=0,b=1,sum;
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
cout<<" ";
}
while(sum<=n)
{
cout<<“a”;
sum=a+b;
a=b;
b=sum;

}

}
return 0;
}

Hey , you print 0 before for loop then start your for loop from i=2 keep printing your elements inside nested loop and just add them after printing to generate next number of sequence

hey, @shdanish1508 simply you take a temp variable and do it please refer to this if you still have doubt(https://ide.codingblocks.com/s/172760) or if you had solved it please mark this doubt as resolved

i am not understanding the code cud you expalin the code again

our fibbonaci pattern is 0,1,1,2,3,5…
1.keep 0 in sum and 1 in adder initially.
2.print sum(=0).
3. now your adder for next element will become this sum (since to generate next element we have to add previous sum the current sum) so store in it a temp and change your sum to next element of pattern sum=sum+adder=1.
4.update temp to the adder(=0)
process will be repeated till your for loop runs.hope it helps.
if still have doubt please ask else please mark this doubt as resolved.thankyou.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.