-->

Facebook

Jasper Roberts - Blog

Wednesday, October 15, 2014

Write a c program to print first n Fibonacci numbers.


#include<stdio.h>
#include<conio.h>

void main()
{
int num1=0, num2=1, num3, n, i;
clrscr();




printf(“Enter N number: ”);
scanf(“%d”,&n);

if(n>2)
{
     Printf(“\n the Fibonacci numbers are:”);
     Printf(“%5d%5d”,num1,num2);
     i = 2;

     while(i<n)
     {
          num3 = num1 + num2;
          printf(“%5d”,num3);
    
          num1 = num2;
          num2 = num3;
          i++;
     }
}
else
     {
          Printf(“\n0 1”);
getch();
}

OUTPUT:
Enter N number: 9

0 1 1 2 3 5 8 13 21

Download
fibonacci series cpu(2110003) in pdf format

No comments:

Post a Comment