Unsolved Programming Questions
Unsolved Programming Questions
Write a C++ program to sum the numbers started by 0 and increment by 2 for ten times using while
loop.
Exercise 2:
Write a C++ program to display the multiples of 3 backward from 33 to 3, inclusive using while loop.
Exercise 3:
Suppose that the input is: 32 53 -10 45 -56 -87 132 165 -999
#include <iostream>
using namespace std;
int main()
{
int num;
int count = 0;
cin >> num;
while (num != -999)
{
cout << num % (count + 1) << " ";
cin >> num;
count++;
}
cout << endl;
return 0;
}
Exercise 4:
Consider the following program.
#include <iostream>
using namespace std;
int main()
{
int num1, num2;
int temp = 0;
cout << "Enter two integers: ";
cin >> num1 >> num2;
cout << endl;
while ((num1 + num2) % 2 != (num1 + num2) % 3)
{
temp = num1 + num2;
num1 = num2;
num2 = temp;
cout << temp << " ";
}
cout << " *" << endl;
return 0;
}
a. What is the output if the input is 10 10?
Exercise 6:
Write a program that uses for loops to perform the following steps:
a. Prompt the user to input two integers: firstNum and secondNum (firstNum must be less than
secondNum).
b. Output all odd numbers between firstNum and secondNum.
c. Output the sum of all even numbers between firstNum and secondNum.
d. Output the numbers and their squares between 1 and 10.
e. Output the sum of the square of the odd numbers between firstNum and secondNum
f. Output all uppercase letters.
Exercise 7:
Suppose that x, y, z, and w are int variables. What is stored in x, y, z, and w after the following
statements execute?
x = 9;
y = x - 4;
z = (y + 7) % 6;
w = (x * z) / y - 3;
z = w + (x - y + 2) % x;
Exercise 8:
Suppose x, y, and z are int variables and x = 18, y = 5, and z = 4. What is the output of each of the
following statements?
a. cout << "x = " << x << ", y = " << y<< ", z = " << z << endl;
b. cout << "5 * x - y = " << 5 * x - y << endl;
c. cout << "Product of " << x << " and " << z << " is "<< x * z << endl;
d. cout << "x - y / z = " << x - y / z << endl;
e. cout << x << " square = " << x * x << endl;
Exercise 9:
Suppose a and b are int variables, c is a double variable, and a = 25, b = 20, and c = 5.0. What is the
output of the following statements?
a. cout << a * 2 * b << endl;
b. cout << a + b / 2.0 + 1.5 * c << endl;
c. cout << a / static_cast<double>(b) << endl;
d. cout << 62 % 28 + a / c << endl;
e. cout << static_cast<int>(c) % 3 + 7 << endl;
f. cout << 22.5 / 2 + 14.0 * 3.5 + 28 << endl;
g. cout << 2 / (c - static_cast<int>(c + 1.2))<< endl;
Type Casting:
Exercise 10:
What will be the output of the following C++ Program?
#include <iostream>
using namespace std;
int main()
{
cout << "static_cast<int>(7.9) = "<< static_cast<int>(7.9)<< endl;
cout << "static_cast<int>(3.3) = "<< static_cast<int>(3.3)<< endl;
cout << "static_cast<double>(25) = "<< static_cast<double>(25)<< endl;
cout << "static_cast<double>(5 + 3) = "<< static_cast<double>(5 + 3)<< endl;
cout << "static_cast<double>(15) / 2 = "<< static_cast<double>(15) / 2<< endl;
cout << "static_cast<double>(15 / 2) = "<< static_cast<double>(15 / 2)<< endl;
cout << "static_cast<int>(7.8 + static_cast<double>(15) / 2) = "<< static_cast<int>(7.8 +
static_cast<double>(15) / 2)<< endl;
return 0;
}
Exercise 11:
What will be the Output of the following C++ Program?
#include <iostream>
int main ()
z = y + x++;
cout << "x = " << x << " y = " << y << " z = " << z << endl;
z = y++ + x;
cout << "x = " << x << " y = " << y << " z = " << z << endl;
z = y++ + x++;
cout << "x = " << x << " y = " << y << " z = " << z << endl;
z = --y + x++;
cout << "x = " << x << " y = " << y << " z = " << z << endl;
z = y + --x;
cout << "x = " + x << " y = " << y << " z = " << z << endl;
z = --y + --x;
cout << "x = " << x << " y = " << y << " z = " << z << endl;
Exercise 12:
Determine the output of the following program.
#include <iostream>
int main()
cout << "num1 = " << num1 << endl; cout << "num2 = " << num2 << endl; cout << "num3 = " << num3 <<
endl;
cout << "num1 = " << num1 << endl; cout << "num2 = " << num2 << endl;
cout << "num1 = " << num1 << endl; cout << "num2 = " << num2 << endl; cout << "num3 = " << num3 <<
endl;