Professional Documents
Culture Documents
Review Questions
int main()
{
int num = 57;
cout << "\n\n Display the operation of pre and post increment and decrement :\n";
cout <<" After pre increment by 1 the number is : " << num << endl;
num = num + 1;
cout <<" After increasing by 1 the number is : " << num << endl; // 79
num--;
cout <<" After post decrement by 1 the number is : " << num << endl;
--num;
cout <<" After pre decrement by 1 the number is : " << num << endl;
num = num - 1;
cout <<" After decreasing by 1 the number is : " << num << endl;
cout << endl;
return 0;
int main()
cout << "\n\n Print the result of some specific operation :\n";
int main()
temp=num2;
num2=num1;
num1=temp;
cout << " After swapping the 1st number is : "<< num1 <<"\n" ;
cout << " After swapping the 2nd number is : "<< num2 <<"\n\n" ;
int x;
cin>> x;
cout<<" "<<x<<x<<x<<x<<endl;
cout<<" "<<x<<x<<x<<x<<endl;
return 0;
int nm1 = 1;
while (true)
++nm1;
if ((nm1 % 3) == 0)
continue;
if (nm1 == 50)
break;
if ((nm1 % 2) == 0)
nm1 += 3;
else
nm1 -= 3;
return 0;
[6] Write a C++ program (include a function in your answer) to add all the numbers from 1 to a given
number.
Add 1 to 4: 10
[8] Write a program that reads in ten whole numbers and that outputs the sum of all the numbers
greater than zero, the sum of all the numbers less than zero (which will be a negative or zero), and the
sum of all the numbers, whether positive, negative, or zero.
[9] Write a program that will ask the user to input n positive numbers. The program will terminate if
one of those number is not positive.
[10] Write a program that determines a student’s grade. The program will read three types of scores
(quiz, mid-term, and final scores) and determine the grade based on the following rules:
-if the average score >= 70% and <90% => grade=B
[11] Write a program that asks the user for an integer number and find the sum of all natural numbers
up to that number.
[12] Write a program that calculates 6^5. Declare your own function to do this.
[13] The program will prompt the user to choose the operation choice (from 1 to 5). Then it asks the
user to input two integer vales for the calculation. See the sample below.
MENU
1. Add
2. Subtract
3. Multiply
4. Divide
5. Modulus
Result: 27
Continue? y
The program also asks the user to decide whether he/she wants to continue the operation. If he/she
input ‘y’, the program will prompt the user to choose the operation gain. Otherwise, the program will
terminate.
#include <iostream>
using namespace std;
int main()
{
int num1, num2, r, sum=0;
#include <iostream>
int main()
int a, b, c;
a = 10;
b = 20;
c = 30;
figureMeOut(a, b, c);
cout << a << " " << b << " " << c;
return 0;
cout << x << " " << y << " " << z << endl;
x = 1;
y = 2;
z = 3;
cout << x << " " << y << " " << z << endl;
}
[16]Show the output of the following program:
int main()
return 0;
[17] write an “overloaded” function called absolute that converts a negative number of either int or
float to an absolute positive number
third = second;
second = first;
first = arr[i];
third = second;
second = arr[i];
third = arr[i];
int main()
mysterious(nums);
return 0;}
int max_count = 0;
int count=1;
if (nums[i]==nums[j])
count++;
if (count>max_count)
max_count = count;
int count=1;
if (nums[i]==nums[j])
count++;
if (count==max_count)
int main()
[20] Write a C++ program to find the largest element of a given array of integers.
(You can assume any number you want)