Tuesday, September 19, 2023

C++ Practice Questions Before If/Else

 Here are the C++ Basic Practice question Before If/Else which will help in logic building \



Basic Arithmetic:

1.Write a code in C++ to display your name, roll number, degree and semester on console in

following way. Use “\t” to give tab space between each field

Please give your C++ code for solving the above question in the space below:

*******************************

Name Roll Number Degree Semester

*******************************

2. Write a program that will take two integers as input , adds them and display results.


3.Ask the user for two numbers , Subtract them and display results.

4.Create a program that multiplies two numbers entered by the user and shows the product.

5.Ask the user to enter two numbers,  display the quotient by dividing them.

6.Ask the user to enter two numbers , divide them and display the remainder  .

7.Calculate the square of a number entered by the user.

8.Calculate the cube of a number entered by the user.

9.Write a code in C++ to display following on console:

*

**

***

****

10.Declare three variables (A,B,C) of type int in C++. Take input from console in each

variable. Now write code such that following is displayed on screen:

A         B        C

[A]*2 [B]*2 [C]*2

[A]+3 [B]+2 [C]+2


Conversion and Calculation:

1.Create a program that converts Celsius to Fahrenheit. Prompt the user for a temperature in     Celsius and display it in Fahrenheit.

2.Prompt the user for the length and width of a rectangle and calculate its area.

3.Ask the user for the radius of a circle and calculate its area.

4.Compute the speed of a car given the distance traveled and the time taken. Prompt the           user  for these values.

5.Calculate simple interest using the principal amount, rate of interest, and time period              entered by the user.

6.Find the ASCII value of a character entered by the user.

7.Create a program that calculates the area of a triangle. Prompt the user for the base and height.

8.Calculate the area of a parallelogram given its base and height. Prompt the user for these values.

9.Calculate the area of a trapezoid. Ask the user for the lengths of the two bases and the height.

10.Convert following algebraic equation into C++ arithmetic expression:

V = IR

Where “R”, “I” and “V” is resistance, current and voltage respectively.

Ask user to enter values for ‘I’ and ‘R’ and display the result of this expression. All variables

can be integers only. For example, if x=2, and a=1, the y should be 15.

11.Single room takes 2 liters of paint mixture whereas 2 liters’ paint mixture cost is 1000 rupees.

Write a C++ program that takes as input the number of rooms to be painted and outputs the total cost to paint

these rooms. (Assume that all rooms are of same standard size.)

12.Write a C++ program that displays a table of 06 entries that contains square and cube of numbers. An excerpt from table is shown.

a    a^2     a^3

2     4        8

3     9        27

13.Suppose ‘x’, ‘y’, and ‘z’ are int variables and ‘w’ and‘t’ are double variables. What value is

assigned to each of these variables after the last statement executes?

x = 17;

y = 15;

x = x + y / 4;

z = x % 3 + 4;

w = 17 / 3 + 6.5;

t = x / 4.0 + 15 % 4 - 3.5;

14.Write a program, which takes an integer as a parameter and display the number in a reverse order. For example, if the user enters the value 12345, your program must display 54321 on the console window.

15.Write a C++ code to make the following pattern (as given below). Input (starting character) will be

given by user through console which is to be stored in a char variable. You are required to print next

three characters according to the given pattern.

Starting Char        Output

A                            C F J

B                            D G K

C                             E H L

Hint:(Use Ascii code to make this program i.e. Ascii code of A is 65).

16.Prompt the user to enter their weight (in kilograms) and height (in meters). Calculate and display their Body Mass Index (BMI) using the formula: BMI = Weight / (Height * Height).

17.Prompt the user to enter two numbers and swap their values without using a third variable.

18.Ask the user for three numbers and calculate and display their average.

19.Prompt the user to enter a character and display its ASCII value.

20.Implement variable swapping without using a third variable, using bitwise XOR.

1 comment:

Ishq Murshid Drama

Ishq Murshid Drama