Ques:-22) Write a program to print Fibonacci Series from 1 to 100.

Here’s a simple C program to print the Fibonacci series from 1 to 100:

				
					#include"stdio.h"
#include"conio.h"
void main()
{
   int f0=0,f1=1,fibbo=1;
   clrscr();
   printf("fibonacci series b/w 1 to 100 is:");
   while(fibbo<=100)
   {
      printf("%d ",fibbo);
      fibbo=f0+f1;
      f0=f1;
      f1=fibbo;
     // printf("%d ",fibbo);
   }
   getch();
}

				
			

Out Put

				
					Fibonacci Series from 1 to 100:
1 1 2 3 5 8 13 21 34 55 89

				
			

Another Example

				
					#include <stdio.h>

int main() {
    int a = 0, b = 1, next;

    printf("Fibonacci Series from 1 to 100:\n");

    // Print the initial term of the series if it is within the range
    if (b <= 100) {
        printf("%d ", b);
    }

    next = a + b;

    while (next <= 100) {
        printf("%d ", next);
        a = b;
        b = next;
        next = a + b;
    }

    return 0;
}

				
			

Explanation:

  1. Initialize two variables a and b with the first two terms of the Fibonacci series, 0 and 1.
  2. Use a while loop to generate the next term of the series by adding the two previous terms.
  3. Check if the next term is within the range (<= 100) and print it.
  4. Update the previous two terms (a and b) with the new values for the next iteration.

Output:

When you run this program, the output will be:

				
					Fibonacci Series from 1 to 100:
1 1 2 3 5 8 13 21 34 55 89

				
			

This output lists all the Fibonacci numbers from the series that fall within the range of 1 to 100.

Scroll to Top