0% found this document useful (0 votes)
54 views

Determine The Output of The Following Program / Code?: Assignment #8

The document contains 3 questions about C++ code snippets. Question 1 has code that outputs the squares of numbers from 3 to 0, then prints the numbers from 0 to 4. Question 2 has code that outputs the results of various operations on an integer n initialized to 4. Question 3 asks about the output and behavior of a code fragment that takes user input for an integer n and conditionally prints output based on its value.

Uploaded by

gohib
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Determine The Output of The Following Program / Code?: Assignment #8

The document contains 3 questions about C++ code snippets. Question 1 has code that outputs the squares of numbers from 3 to 0, then prints the numbers from 0 to 4. Question 2 has code that outputs the results of various operations on an integer n initialized to 4. Question 3 asks about the output and behavior of a code fragment that takes user input for an integer n and conditionally prints output based on its value.

Uploaded by

gohib
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ITP Assignment

Assignment #8

C++ Output Questions

Question 1:
Determine the output of the following program / code?
#include <iostream>
int main() {
int n = 3;
while (n >= 0)
{
cout << n * n << endl;
--n;
}
cout << n << endl;
while (n < 4)
cout << ++n << endl;
cout << n << endl;
while (n >= 0)
cout << (n /= 2) << endl;
return 0;
}

Question 2:
#include <iostream>
using namespace std;
int main() {
int n;
cout << (n = 4) << endl;
cout << (n == 4) << endl;
cout << (n > 3) << endl;
cout << (n < 4) << endl;
cout << (n = 0) << endl;
cout << (n == 0) << endl;
cout << (n > 0) << endl;
cout << (n && 4) << endl;
cout << (n || 4) << endl;
cout << (!n) << endl;
return 0;
}

Page1/2
ITP Assignment

Question 3:
Answer the questions below concerning the following fragment of code.
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter an integer: ";
cin >> n;
if (n < 10)
cout << "less than 10" << endl;
else if (n > 5)
cout << "greater than 5" << endl;
else
cout << "not interesting" << endl;
return 0;
}

a. What will be the output of the fragment above if the interactive user
enters the integer value 0?
b. What will be the output of the fragment above if the interactive user
enters the integer value 15?
c. What will be the output of the fragment above if the interactive user
enters the integer value 7?
d. What values for n will cause the output of the fragment above to be "not
interesting"?

---------------------------------------------------------------------------------------

Page2/2

You might also like