Determine The Output of The Following Program / Code?: Assignment #8
Determine The Output of The Following Program / Code?: Assignment #8
Assignment #8
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