0% found this document useful (0 votes)
142 views5 pages

Lab 2 Exercise

The document contains 18 questions related to programming fundamentals and algorithms. It asks the student to write algorithms and flowcharts to solve problems involving logical operations, conditionals, variables, basic math, and more. It also contains questions evaluating expressions and defining equations in code. The final questions cover naming conventions for variables.
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)
142 views5 pages

Lab 2 Exercise

The document contains 18 questions related to programming fundamentals and algorithms. It asks the student to write algorithms and flowcharts to solve problems involving logical operations, conditionals, variables, basic math, and more. It also contains questions evaluating expressions and defining equations in code. The final questions cover naming conventions for variables.
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/ 5

Programming Fundamentals

Lab 2
FARAH SADIA

Exercise:

Question # 01:Write an algorithm which takes 10 input numbers and display the
second largest number.

Question # 02: Write an algorithm Print Hello World 10 times

Question # 03: Write an algorithm to check whether a given number is prime or not.

Question # 04: Draw a flowchart to log in to facebook account

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:

No. of Units consumed Cost per unit


Programming Fundamentals
Lab 2
FARAH SADIA

1 - 100 Rs. 05.25

101 - 200 Rs. 07.75

201 - 300 Rs. 08.92

301 - 400 Rs. 11.55

400+ Rs. 12.71

Question # 10: Perform all preprogramming phase a company is giving an increment


to its employees who have served longer than 3 years. Write a program that will require the
employee to input year of service and their salary. Your program then has to calculate the
increment in salary based on the table below.

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 # 13: Write if statements to do the following:


1. If character variable taxCode is ’T’, increase price by adding the taxRate percentage
of price to it.
2. If integer variable opCode has the value 1, read values for X and Y and calculate
and print their sum.
3. If integer variable currentNumber is odd, change its value so that it is now 3 times
current Number plus 1 otherwise change its value so that it is now half of current
Number.
4. Assign true or 1 to the boolean variable leapYear if the integer variable year is a leap
year. (Aleapyear is a multiple of 4, and if it is a multiple of 100, it must also be a
multiple of 400.)

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 # 15: Find the result of the following operations:


a. 5+4
b. 10/2
c. True OR False
d. 20 MOD 3
e. 5< 8
f. 25 MOD 70
g. “A” > “H”
h. NOT True
i. 25/70
j. False AND True
k. 20 * 0.5
l. 35 <= 35
m. 35/7
n. False OR False
o. True AND True
p. 50 MOD 5
q. -35 < 67
r. 4.0 ^ 3
s. 60\9
t. 35 < 35
u. True AND 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 # 17: Write the following equations in computer form:


a. X = Y + 3Z – (Z + Y)/ (Z – 3)
b. X = 5Y + (3Z – 1)/4(3Z + 1) – Y
c. X = (X – Y)2

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?

a. City Name referencing the name of a city.


b. Client-name referencing a client name.
c. City/State referencing a city and state.
d. LN referencing a last name.
e. Street address
f. Street_Address_for_Joe’s_Hardware_Supply_Incorporated_Client

You might also like