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

Program Code:
#include<iostream.h>
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()
{
item a;
a.sum=1;
a.fibo(1,1);
return 0;
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: