C Program To Generate Fibonacci Series using For Loop

preview_player
Показать описание

Lets write a C program to generate Fibonacci Series, using for loop.

Fibonacci Series is a series of numbers where the first two Fibonacci numbers are 0 and 1, and each subsequent number is the sum of the previous two. Its recurrence relation.

C Programming Interview / Viva Q&A List

C Programming: Beginner To Advance To Expert
Рекомендации по теме
Комментарии
Автор

Superb 👌 video 📸 & also you gave the browser link..
Superb 👌👌👌 well done

yuvisaravana
Автор

This method does not account for when the input is 0 or 1. to include zero and one into the computation, consider this code:

int n, first = 0, second = 1, next, c;

printf("Enter the number of terms: ");
scanf("%d", &n);

printf("First %d terms of Fibonacci series:\n", n);

for (c = 0; c < n; c++) {
if (c <= 1)
next = c;
else {
next = first + second;
first = second;
second = next;
}
printf("Fibonacci number %d is %d\n", c, next);
}

stanleymartin
Автор

I am blown up by how easy you made it.

ohistit
Автор

my one suggestion is please sperate the list of program according to the tropic.. finding the program is bit messy... IT is good u have one master playlist where all the program and rules regarding C is there... APART from that..u must create a separate playlist also for the separate tropic...

nbk
Автор

Sir what will be the output if we enter the term 1

arfathraza
Автор

Can you expalin why count = 3 ???please

moonking_
Автор

There is a small mistake. If you input 1 it will give 0, 1. rather then only 0. so, you should use if command. thanks!

How i solved. I am here to find any short process . If you have, please reply....


#include <stdio.h>

int main()

{int a, n ;
printf("Enter a number:");
scanf("%d", &a);
int i1 =0;
int i2= 1;

if(a<=2){
printf("%d\n", 0);
}
if(a==2){
printf("%d\n", 1);
}
if ( a>>3){
printf("%d\n", 0);
printf("%d\n", 1);
}

for ( n=3; n<=a ; n++){



int fib=i1+i2;
printf("%d\n", fib);

i1=i2;
i2=fib;


}

return 0;
}

jishanahmed