Sie sind auf Seite 1von 1

PROGRAMMING FUNDAMENTALS

Assignment No: 2
Decision Structure
BS(IT)- Due Date: November 19 th , 2019, Beginning of Class
BS(CS)- Due Date: November 21 st , 2019, Beginning of Class
Instructor: Najia Saher email: najia.saher@iub.edu.pk

Instructions: Do not code on a computer. Solve the questions by hand on paper. Do your work neatly.

Question 1: Write a program that reads an integer and prints whether it is negative, zero, or positive.

Question 2: Write a program to check whether the given number is even or odd (using ? : ternary operator )

Question 3: Write a program to calculate the total expenses. Quantity and price per item are input by the user
and discount of 10% is offered if the expense is more than 5000.

Question 4: Write a program that reads a temperature value and the letter C for Celsius or F for Fahrenheit. Print
whether water is liquid, solid, or gaseous at the given temperature at sea level.
Help:
For Fahrenheit:
Temperature reading less than or equal to 32 = Solid
Temperature reading greater than 32 and less than 212 = Liquid
Temperature reading greater than or equal to 212 = Gaseous
For Celsius:
Temperature reading less than or equal 0 = Solid
Temperature reading greater than 0 and less than 100 = Liquid
Temperature reading greater than or equal to 100= Gaseous

Question 5: Write a program that reads four integers and prints “two pairs” if the input consists of two matching
pairs (in some order) and “not two pairs” otherwise.
For example,
1 2 2 1 two pairs
1 2 2 3 not two pairs
2 2 2 3 two pairs
2 2 2 2 two pairs

Question 6: Write a program that reads amount and Check if amount is less than 1000. If not, then print “program
ends because amount is larger than 1000” but if yes, then Print “ amount is smaller than 1000 so please go into this
if/else” and inside this if/else , check the followings: Is amount less than 500 too , then print “stay in this if and go
to its nested if” and again check, is amount less than 300 too , then print “oh! Ok , it's a small amount entered”
else , go into one more if inside else part and check if amount is not equal to 1000, then print “ “oh! Ok , it's silently
larger amount entered” .
1 Assignment: Programming Fundamentals

Das könnte Ihnen auch gefallen