FIBONACCI SERIES REVERSE | Sololearn: Learn to code for FREE!

+29

FIBONACCI SERIES REVERSE

[REVERSE] FIBONACCI SERIES [C] 1.i want to modify this code in reverse order. https://code.sololearn.com/cmMF3eHZ2C7h/?ref=app 2.how to print the Fibonacci series in reverse order with explaination...

11/15/2020 3:16:57 AM

ℜøźєη⇝gнσѕт♡

7 Answers

New Answer

+12

Ashwin Jeyaraman thank you 😊 but I already get answer...i wanted to modify my code

+9

PÃŁŁÃVÎ JHÁ Thank you

+4

Store the results in an array then loop over the array in reverse order outputting them.

+3

#include <stdio.h> #include <stdlib.h> int main() { int num1=0,num2=1,num3=0; int N; int ar[101]; int flag=0; scanf("%d",&N); if(N==1){ printf("%d\n%d",num1,num1); exit(0); } if(N==2){ printf("%d %d\n%d %d",num1,num2,num2,num1); exit(0); } else{ for(int i=2;i<N;i++){ if(flag==0){ printf("%d %d ",num1,num2); flag=1; } num3=num1+num2; num1=num2; num2=num3; printf("%d ",num3); ar[0]=0; ar[1]=1; ar[i]=num3; } } printf("\n"); for(int i=N-1;i>-1;i--){ printf("%d ",ar[i]); } return 0; }

+2

Just reverse the pattern of the array

0

Alright 👍