You are on page 1of 2

Computer Programming

Spring 2023
HW 1

1. Explain the need for compiler directives like: #include <iostream>

2. Suppose that the input is:

58 23 46 75 98 150 12 176 145 -999

What is the output of the following program?

#include <iostream>

using namespace std;

int main()
{
int num;
cin >> num;

while (num != -999)


{
cout << num % 25 << " ";
cin >> num;
}
cout << endl;

return 0;
}

3. Suppose that the input is 38 35 71 14 -1.

What is the output of the following code? Assume all variables are properly
declared.

cin >> sum;


cin >> num;
for (j = 1; j <= 3; j++)
{
cin >> num;
sum = sum + num;
}

cout << "Sum = " << sum << endl;

4. Suppose the input is 5. What is the output of this code:

cin >> num;


if (num > 5)
cout << num;
num = 0;
else
cout << "Num is zero" << endl;

5. What will this program do?

int main()
{
int num1, num2, larger;
if (num1 > num2);
larger = num1;
else
larger = num2;
return 0;
}

You might also like