Write a C C++ program to generate fibonacci series

 

Flowchart

Fibonacci series upto n flowchart

 

Coding in C

#include<stdio.h>
int main()
{
int a=0,b=1,c=1,n;
printf(“Enter n: “);
scanf(“%d”,&n);
printf(“%d\n”,a);
printf(“%d\n”,b);
while(c<=n)
{
printf(“%d\n”,c);
a=b;
b=c;
c=a+b;
}
return 0;
}

 

Coding in C++

#include<iostream>
using namespace std;
int main()
{
int a=0,b=1,c=1,n;
cout<<“Enter n: “;
cin>>n;
cout<<a<<“\n”;
cout<<b<<“\n”;
while(c<=n)
{
cout<<c<<“\n”;
a=b;
b=c;
c=a+b;
}
return 0;
}

 

Output

Fibonaccy series upto n output

 

Published by

admin

I am a computer teacher, programmer and web developer