Answer to Question #16983 in C++ for martin

Question #16983
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();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS