C++ program to illustrate the static variable functionality using sum of a Fibonacci series - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Monday, August 21, 2017

C++ program to illustrate the static variable functionality using sum of a Fibonacci series

Write a C++ program to illustrate the static variable functionality using sum of a Fibonacci series as an example.


 Output:
      Sum=232

Program:

#include<iostream>
using namespace std;

class item
{
public:
static int sum;
void fibo(int f,int s)
{
if(s>100)
cout<<"Sum="<<sum<<endl;
else
{
sum+=s;
fibo(s,f+s);
}
}
};
int item::sum;

int main(int argc, char** argv) {
    item a;
    a.sum=1;
    a.fibo(1,1);
return 0;

}

No comments:

Post a Comment