0% found this document useful (0 votes)
15 views4 pages

Lec 5 - Practice Questions

Uploaded by

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

Lec 5 - Practice Questions

Uploaded by

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

Practice Questions

Attempt All Questions


1. Following are programs expressed as English statement. Write only the programing
statements for actual program and their output.
The variable x starts with the value 10
The variable y starts with the value 2
The variable z starts with the value 4
Store the value of x times y in x
Store the value of y times z in y
Add x and z and store result in y
What is the value of y if output on screen

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

3. Which of the following is a Character Literal


‘A’
“A”
4. Assuming the size of data types required in memory is 1B,4B,8B for Character, integer
and double respectively. How many bytes the following declaration required

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

7. How the group of statements are enclosed to treat as a block.


8. Assume w = 5 , x = 4 , y = 8 , and z = 2. What value will be stored in result in each of
the following statements?
result = x + y ;
result = z * 2 ;
result = y / x ;
result = y - z ;
result = w % 2;

9. Write expressions for the following algebraic expressions.

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

You might also like