0% found this document useful (0 votes)
4 views3 pages

Midterm Practice Problems

Uploaded by

mohammad3mhamdy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Midterm Practice Problems

Uploaded by

mohammad3mhamdy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Practice problems

1. Write a C++ program to print all the integer numbers that are divisible by 7 in the range 1
to 100.

2. Write a C++ program to print all the integer numbers that are not divisible by 5 and not
divisible by 9 in the range 1 to 100.

3. Write a C++ program to generate and print out the following series:
1 2 4 8 16 32 64 128 256 4.

4. Write a C++ program that takes a big integer number (num) and displays the greatest
digit in that big number (num). For example, if it takes 10567595 asthe big integer, then
it displays 9 and if it takes 4054351, it displays 5.

5. The Pythagorean Theorem states that the sum of the squares of the sides of a right
triangle is equal to the square of the hypotenuse. For example, if two sides of a right
triangle have lengths 3 and 4, then the hypotenuse must have a length of 5. The integers
3, 4, and 5 together form a Pythagorean triple.
There is an infinite number of such triples.
Given two positive integers, m and n, write a modular C++ program to validate that m >
n, and produce the Pythagorean triple which can be generated by the following formulas:
Side1 = m2-n2
Side2 = 2*m*n
Hypotenuse = square root of (side12 + side22)

6. Show what the following programs do:


void main()
{
int s = 0, k = 0;
for (int c = 1; c <= 20; c++){
if ((c % 3 == 0) && (c % 6 != 0))
{
s += c;
k++;
}
}
cout << setw(3) << s << setw(3) << k << endl;
}
void main()
{
int x = 3, y = 1, z;
while (x > 1)

{
z = y++ / 2 + --x;

}
cout << "X= " << setw(3) << x << " Y= "<< setw(3) << y << " Z= " << setw(3) <<z<<endl;
}

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

void main()
{
const int ten = 10; int t = 0, s = 9, b = 0, c = 0, d;
int n = 35078;
do
{
d = n%ten;
t = t + d;
if (d > b)
b = d;
if (d < s)
s = d;
if (d == 0)
c++;
n = n / ten;
} while (n != 0);
cout << "Value 1 =" << setw(4) << t << endl;
cout << "Value 2 =" << setw(4) << s << endl;
cout << "Value 3 =" << setw(4) << b << endl;
cout << "Value 4 =" << setw(4) << n << endl;
}

7. Write a c++ program to output the following

shape:1
12
123
1234
12345
123456
8. Write a function int power(int num, int p) that calculates the value of (nump). [Note: If p is 0, the
function returns 1 and if p is 1 the function returns num]

9. Write a program in C++ to convert temperature in Fahrenheit to Celsius.

Sample Output:
Convert temperature in Fahrenheit to Celsius:
---------------------------------------------------
Input the temperature in Fahrenheit : 95
The temperature in Fahrenheit : 95
The temperature in Celsius : 35

You might also like