Lec 5 - Practice Questions
Lec 5 - Practice Questions
2. Following algorithm has an error. The program is supposed to ask the user for the
length and width of a rectangular room, and then display the room’s area. The program
must multiply the width by length in order to determine the area.
area = width into length
Display “What is Room’s Width”
Input width
Display “What is Room’s Length”
Input length
Display area
int x,y,z;
char a,b;
double j,k;
5. How would you consolidate the following definitions into one statement.
int x = 7;
int y = 20;
int z = 28;
6. How many operands does each of the following types of operator
require? Unary , Binary and Ternary
10. Design an algorithm to find the perimeter and area of rectangle. Formula used to find the
solution are
Perimeter = 2 * (length + width)
Area = length * width
11. Design an algorithm to calculate the sales tax and price of an item sold in a particular
state. The sales tax is calculated as follows. The state’s portion of sales tax is 4% and
the city’s portion of sales tax is 1.5%. if cost of item is more than 50000 then a luxury
tax of 10% is applicable.
12. Given the radius, in inches, and price of pizza, design an algorithm to find the price
of pizza per square inch.
13. To get the average of a series of values, you add the values up and then divide the sum by
the number of values. Write a complete program that stores the following values in five
different variables: 28 , 32 , 37 , 24 and 33. The program should first calculate the sum of
these five number and then stores then in a different variable named sum. Then the
program should display the average on screen. [Use data types correctly]
14. Following program has error, locate the error and rewrite the code by mentioning error
in comment.
15. Following program has errors, locate the errors and rewrite the code by mentioning error
in comment.
16. Assuming x is 5, y is 6 , and z is 8. Which of the following statement result true or False