Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Branching - Classwork Programs

1. Write a program to read a number, print absolute value of it using if statement and conditional
operator.

2. Write a program to read the 3 coefficients from user, calculate and print solutions of a second
degree quadratic equation ax2 + bx + c = 0

3. Write a program to read a number and check whether is it an odd number or


even number, print proper message.

4. A year is said to be a leap year if it is divisible by 4 but not by 100, except it is divisible
by 400. Write a program to read a year, check is it a leap year or not, print proper
message

5. Write a program to read an alphabet from user, change the case of it and print

6. Write three different programs to read three numbers, print largest among them using (i)
nested if (ii) else if ladder (iii) conditional operator.

7. Write a program to accept marks of 4 individual papers out of 100 each of a student and grade
the student based on % mark as follows using nested if (print distinction first)
% marks grade
% mark >= 75 Distinction
60 <= % mark < 75 First Class
50 <= % mark < 60 Second Class
35 <= % mark < 50 Pass
% mark < 35 Fail

8. Write a program to accept marks of 4 individual papers out of 100 each of a student and grade
the student based on % mark as follows using else if ladder (print fail call first)
% marks grade
% mark >= 75 Distinction
60 <= % mark < 75 First Class
50 <= % mark < 60 Second Class
35 <= % mark < 50 Pass
% mark < 35 Fail

9. Write a program to categorize a single character that is entered at the terminal as a digit, lower
case letter, upper case letter, punctuation, space or any other character.

10 Write a program to read two values and an arithmetic operator, evaluate the of basic
arithmetic expression using switch statement
11. Write a program to accept marks of 4 individual papers out of 100 each of a student and grade
the student based on % mark as follows using switch statement
% marks grade
% mark >= 70 Distinction
60 <= % mark < 70 First Class
50 <= % mark < 60 Second Class
40 <= % mark < 50 Pass
% mark < 40 Fail
Branching Homework
1. What is meant by control flow in C language? Mention different control structure
available in C.

2. Mention four different methods of branching in C language. With help of block diagrams
describe simple if construction and else if construction.

3. With help of block diagrams describe nested if construction and if else ladder construction.

4. Taking an example of finding out largest number among two, describe else if

5. With help of block diagrams describe else if construction and conditional operator..

6. With help of a block diagram describe switch statement. Explain the importance of break
and default statements.

Branching - Homework Programs


1. A set of two liner equations with two unknowns x1 and x2 are given below
ax1 + bx2 = m
cx1 + dx2 = n

The set has unique solutions as


md  bn na  mc
x1  x2 
ad  cb ad  cb

provided (ad-cb)  0

Write a program to read the values a, b, c, d, m and n and compute and print x1 and x2.

2. Write a program to read three sides of a triangle a, b, c. Check whether its area is higher
than perimeter. Print proper message.
area  s * ( s  a) * ( s  b) * ( s  c)

s  ( a  b  c) / 2

3. For a certain electrical circuit with an inductance L and resistance R, the damped natural
frequency is given by
1 R2
f  
LC 4C 2
Write a program to read C in F, L in mH and R in K and calculate frequency. Program should
print C, L, R and frequency.

4. Write a program to read an alphabet, check whether is it a vowel or not, print proper
message.
5. Write a program to read three integer values from the keyboard and check whether it
form a right-angled triangle or not. Program should print a proper message.

6. Write a program to read three numbers, if sum of these numbers is between (inclusive)
201 and 300 find its square root
301 and 400 find its cube root
>400 find its fourth root
Print all three numbers, sum and the result

7. Write two different programs that will read the value of x and evaluate the following function
using
(i) else if statement
(ii) conditional operator
| 1 for x > 0
sign = | 0 for x = 0
| -1 for x < 0

8. An electric company charges its consumers as follows


Consumption unit rate of charge
0-200 2.50 per unit
201-400 Rs 500 + 3.00 per unit for excess of 200
401-600 Rs 1100 + 3.50 per unit for excess of 400
above 600 Rs 1800 + 4.00 per unit for excess of 600
Write a program to read the customer number and power consumed and print the amount to
be paid.

9. Write a program to read 3 values, calculate and print average of smallest and largest
among them. Use if construction to get smallest value and conditional operator to get
highest value.

10. Write a program to read three integer values from the keyboard and check whether it
form a right-angled triangle or not. Program should print a proper message.

11. A travel agency provides services for car, bus, air and ship travel. Write a program to get
response from user and choose proper menu using switch statement. Provision should be made
to accept response in lower case or upper case.

You might also like