Lab 2 Exercise
Lab 2 Exercise
Lab 2
FARAH SADIA
Exercise:
Question # 01:Write an algorithm which takes 10 input numbers and display the
second largest number.
Question # 03: Write an algorithm to check whether a given number is prime or not.
Question # 05: Perform all preprogramming phase a farmer has some chickens and
some goats. Together there are 43 heads and 108 legs. How many chickens does the
farmer have? How many goats?
Question # 06: Perform all preprogramming phase which takes 8 numbers as input
in variables a-h, then computes the following formula and displays the output to screen.
Question # 07: Perform all preprogramming phase Raza was not feeling well; he
went to the doctor. Doctor check Raza and prescribe him 3 tablets in the morning, 5
tablets in the afternoon and 3 tablets at night. Based on the input find out the total
number of tablets Raza takes in a day.
Question # 08: Perform all preprogramming phase that asks user to give number of
days as input and returns the number of years, weeks, and days. Assume every year
has 365 days and every month is of 30 days.
Question # 09: Write the algorithm and flowchart Take no. of units consumed from
user, then calculate his/her Electricity bill based on following information:
Salary Increment
Salary>=40000 2%
40000 PKR < Salary >=20000 2.5%
PKR
20000 PKR < Salary >=15000 4.0%
PKR
15000 PKR < Salary >=10000 7.0%
PKR
Question # 11: Write an algorithm that raise ‘a’ to the power ‘b’ and store in exp. where
‘a’ and ‘b’ are user inputs.
Programming Fundamentals
Lab 2
FARAH SADIA
Question # 12: Write an algorithm that produce table of a user given number.
Question # 14: Name the data type for each of the following constants. Explain your
answer.
a. 5.38
b. “87654”
c. True
Programming Fundamentals
Lab 2
FARAH SADIA
d. “A”
e. “707-434-5555”
f. “New York”
g. -389
h. 2.45E6
i. 48976.0
j. False
Question # 16: Evaluate the following equations, given the values A = 12, B = 3, C = 6,
D = 2:
a. F=A + B/C – D ^ 2
b. F=(A + B)/C – D ^2
c. F = A + B/(C – D ^2)
d. F=(A + B) MOD C
e. F=(A + B)/ D ^2
Programming Fundamentals
Lab 2
FARAH SADIA
Question # 18: Create a table that gives all possible answers for the following logical
equations. (Include the structure of the order of processing—see page 33 for example.)
Make clear how you set up the table.
a. R = A OR B
b. R = NOT A OR B
c. R = A AND B AND (B OR C)
d. R = NOT (A OR B) AND NOT (B OR C)
e. R = B AND NOT (A OR C) OR NOT (B AND C)
Question # 19: Evaluate the following for the values A = 5, B = 2, C = True, D = False.
(Include the structure of the order of processing.)
a. R = A + 3 > B - 1 AND C OR D
b. R = NOT C OR D OR A - 3 <= B
Question # 12:
What is wrong with these variable names? Can you correct them?