What is the output of following code include using namespace
What is the output of following code? #include using namespace std; int main () {int num - 0; int count; int y - 0; for (count - 1; count
Solution
Question 1:
a. -1 1 3 5 7 6
here is for loop expersion works in iteration
// 3 * (0) + (0 - 1) = -1
// 3 * (1) + (0 - 2) = 1
// 3 * (2) + (0 - 3) = 3
// 3 * (3) + (0 - 4) = 5
// 3 * (4) + (0 - 5) = 7
finally print 6
Question 2:
int i = 0,value = 0;
for(i = 0; i<= 20 ; i++)
{
if(i%2== 0 && i <= 10)
value = value +i * i;
else if ( i %2 == 0 && i > 10)
value = value + i;
else
value = value - i;
}
cout << \"value = \" << value<< endl;
