How static variable is different from the simple class variable?
WAP to add first seven terms of the following series:
1/1! + 2/2! + 3/3! +........
Explain the effect of static variable on the output of the program?
1
Expert's answer
2012-10-25T11:55:14-0400
#include<iostream> #include<conio.h> using namespace std; void main() { static int sum = 0; int factorial = 1;
for(int i = 1; i < 7; i++) { & for(int j = 1; j < i;j++) { & factorial +=j; & } & sum += i/factorial; & factorial = 0; } cout << sum << endl; _getch(); }
Comments
Leave a comment