This blog consists of C and C++ programs. C and C++ programming is the basics to learn any programming language. Most of the programs are provided with their respective outputs. This blog also contains Data Structures programs using Object-Oriented Programming (C++). Some of the best books for learning C and C++ programming are also mentioned.

Showing posts with label Fibonacci Series. Show all posts
Showing posts with label Fibonacci Series. Show all posts

Wednesday, 5 June 2013

Program to find the Fibonacci Series using FOR loop (4)

#include<iostream.h>
#include<conio.h>
main()
{
int a, b, c, n;
a=0;
b=1;
c=0;
int i=0;
clrscr();
cout<<"Enter the value of n";
cin>>n;
cout<<'\n'<<a<<'\n'<<b;
for(i=2;i<n;i++)
{
c=a+b;
cout<<'\n'<<c;
a=b;
b=c;
}
getch();
}

Program to find the Fibonacci Series using DO WHILE loop (3)



#include<stdio.h>
void main()
{
int a,b,c,n,i;
clrscr();
a=0;
b=1;
i=3;
printf("Enter the number of terms: ");
scanf("%d",&n);
printf("%d\n%d",a,b);
do
{
c=a+b;
printf("\n%d",c);
a=b;
b=c;
i=i+1;
}
while (i<=n);
getch();
}

Program to find the Fibonacci Series using FOR loop (2)



#include<stdio.h>
void main()
{
int a,b,c,i,n;
a=0;
b=1;
clrscr();
printf("Enter the number of terms: ");
scanf("%d",&n);
printf("%d\n%d",a,b);
for(i=3;i<=n;i++)
{
c=a+b;
printf("\n%d", c);
a=b;
b=c;
}
getch();
}

Program to find the Fibonacci Series using FOR loop (1)



#include<stdio.h>
void main()
{
int a,b,c,i,n;
clrscr();
a=-1;
b=1;
printf("Enter the number of terms: ");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
c=a+b;
printf("%d\n", c);
a=b;
b=c;
}
getch();
}