Â
In this, we are going to see Functions, the program is based on function which Calculates, Profit or Loss.
The code given below can be used for TURBO C++ Compiler:-
#include<iostream.h>
#include<conio.h>
// creating a fibonacci function
int fibonacci()
{
clrscr();
int n;
int a = 0;
int b = 1;
int c;
int fib = 0;
cout << "enter value for n\n";
cin >> n;
cout<<"Fibonacci series is \n";
cout << "0 1 ";
do
{
c = a + b;
cout << c << " ";
a = b;
b = c;
n--;
} while (n > 2);
return n;
}
void main()
{
// calling fibonacci function
fibonacci();
getch();
}
The code given below can be used for g++/gcc Compiler:-
#include<iostream>
using namespace std;
int fibonacci()
{
int n;
int a = 0;
int b = 1;
int c;
int fib = 0;
cout << "enter value for n\n";
cin >> n;
cout<<"Fibonacci series is \n";
cout << "0 1 ";
do
{
c = a + b;
cout << c << " ";
a = b;
b = c;
n--;
} while (n > 2);
return n;
}
int main()
{
fibonacci();
return 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP