0% found this document useful (0 votes)
14 views

Hands-On - Control Flow Statements - Questions

practices of control flow

Uploaded by

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

Hands-On - Control Flow Statements - Questions

practices of control flow

Uploaded by

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

HANDS-ON

SDE Readiness Training

Hands-on No. :3

Topic : Control Flow Statements

Date : 17.09.2024

Solve the following problems

Question
Question Detail Level
No.

1 Take values of length and breadth of a rectangle from user and Easy
check if it is square or not.

Sample Input: 5, 3
Sample Output: Not a Square
Sample Input: 7, 7
Sample Output: Square
2 Write a program to check whether the given number is odd or Easy
even.

Sample Input: 20
Sample Output: Even
Sample Input: 87
Sample Output: Odd
3 Write a program to get a number from the user and print whether Easy
it is positive, negative or zero.

Sample Input: 56
Sample Output: positive
Sample Input: -235
Sample Output: negative
4 Write a program to check whether a kid is eligible for kinder Easy
garden school admission. If a child is of age 4 or more then
he/she is eligible.
Sample Input: 4
Sample Output: Eligible
Sample Input: 2
Sample Output: Not Eligible

It is going to be hard but, hard does not mean impossible.


1
HANDS-ON
SDE Readiness Training
5 Write a program to find the mobile chosen is within the budget Easy
or not. To find the budget mobiles is based on the below-
mentioned criteria,
a) If the cost of the mobile chosen is less than or equal to
15000 then display it as "Mobile chosen is within the
budget"
b) If the cost of the mobile chosen is greater than 15000
then display it as “Mobile chosen is beyond the budget”

Sample Input: 12000


Sample Output: Mobile chosen is within the budget
Sample Input: 22000
Sample Output: Mobile chosen is beyond the budget
6 Given 2 integer values, ‘a’ and ‘b’, return their sum. However, Easy
"teen" values in the range 13…19 inclusive, are extra lucky. So,
if either value is a teen, just return 19.

Sample Input: 3, 4
Sample Output: 7
Sample Input: 13, 8
Sample Output: 19

7 Kumar is purchasing certain items in a store. While purchasing Easy


certain items, a discount of 10% is offered to his if the quantity
purchased is more than 1000. Help, Kumar to calculate the total
expenses.

Sample Input: 1200, 15.50


Sample Output: 16740.0
Sample Input: 200, 15.50
Sample Output: 3100.0

8 In Chai Sung’s family the birthright will be given to the firstborn Easy
as a custom. Who will get the birthright among his three sons
Choi Sung, Moui Sung, and Bhoi Sung if their ages are the input
values?

Sample Input: 34, 26, 18


Sample Output: Choi Sung
Sample Input: 28, 16, 30

It is going to be hard but, hard does not mean impossible.


2
HANDS-ON
SDE Readiness Training
Sample Output: Bhoi Sung

9 Write a program to check error in marks entry while user enters Easy
the marks in the system. Consider Error as marks entered less
than 0 and more than 100.

Sample Input: 83

Sample Output: Valid entry

Sample Input: 101

Sample Output: Invalid entry

Sample Input: -6

Sample Output: Invalid entry

10 Write a program that accepts three numbers from the user and Easy
prints "increasing" if the numbers are in increasing order,
"decreasing" if the numbers are in decreasing order, and
"Neither increasing or decreasing order" otherwise.

Sample Input: 3 6 8
Sample Output: Increasing order
Sample Input: 9 5 1
Sample Output: Decreasing order
Sample Input: 4 9 2
Sample Output: Neither increasing nor decreasing order

11 Smith and John, grade 3 students playing number games. When Easy
Smith gives a number John will say the natural numbers up to
that number but in reverse order. Shia, their friend will say the
sum of those numbers. Help John and Smith with your program.

Sample Input: 4
Sample Output: 4 3 2 1 , 10
Sample Input: 7
Sample Output: 7 6 5 4 3 2 1 , 28
12 Kittu the ‘Giant Ant’ has 100 rooms in its colony. All the ants in Easy
the colony can crawl from 1 room to another, from there to
another and so on. But our ‘Kittu’ has a special power that
makes him to jump from one room to next 10th room directly.

It is going to be hard but, hard does not mean impossible.


3
HANDS-ON
SDE Readiness Training
That is room no 1 to room no 11 or 3 to 13… But poor ‘Kittu’
don’t know to calculate/find which room that he can jump next.
Help him saying all the room numbers to climb up. His starting
room number can be the input.

Sample Input: 2
Sample output: 2 12 22 32 … 92
Sample Input: 5
Sample Output: 5 15 25 35 … 95

13 Write a program to print the numbers from 1 to 20 other than Easy


the given number. Input should be between 1 to 20.

Sample Input: 6
Sample Output: 1 2 3 4 5 7 8 9 10 11 12 13 14 15 16 17 18 19
20
Sample Input: 17
Sample Output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19
20
Sample Input: 23
Sample Output: Invalid Input
14 Write a program to print only the numbers divisible by 3 and 5 Easy
for a given number from 1.
Sample Input: 20
Sample Output: 3 5 6 9 10 12 15 18 20
Sample Input: 40
Sample Output: 3 5 6 9 10 12 15 18 20 21 24 25 27 30 33 35
36 39 40
15 Jack and Emma are playing a number game. Jack should say the Easy
sum of the numbers that Emma says. He should sum until Emma
says ‘zero’. Help Emma to check if Jack is right or not by telling
her the answer.

Sample Input: 2 5 9 4 0
Sample Output: 20
Sample Input: 6 8 2 5 3 9 0
Sample Output: 33

It is going to be hard but, hard does not mean impossible.


4
HANDS-ON
SDE Readiness Training
16 Write a program to print ‘odd’ or ‘even’ number series based on Easy
the given number. That is if the input is an odd number, then it
should generate the odd number series from 1 to the given
number inclusive. If it is even, then it should generate the series
from 2 to that number.

Sample Input: 13
Sample Output: 1 3 5 7 9 11 13
Sample Input: 16
Sample Output: 2 4 6 8 10 12 14 16
17 Given a number, Find the factorial of the given number using Easy
iteratives.

Sample Input: 5
Sample Output: 120
Sample Input: 7
Sample Output: 5040
18 There is a movie club for under 20 in the city, where the entry is Medium
age restricted. Based on their age allow them into either
‘Cartoon Club’ or ‘Teens Club’.

Sample Input: 10
Sample Output: Cartoon Club
Sample Input: 15
Sample Output: Teens Club
Sample Input: -10
Sample Output: Invalid Age
Sample Input: 25
Sample Output: Not Allowed
19 Write a program if an integer variable currentNumber is odd, Medium
change its value so that it is now 3 times currentNumber plus 1,
otherwise change its value so that it is now half of
currentNumber.

Sample Input: 17
Sample Output: 52
Sample Input: 26

It is going to be hard but, hard does not mean impossible.


5
HANDS-ON
SDE Readiness Training
Sample Output: 13

20 Write a program to read an integer variable ‘Code’. If the Code Medium


value is 1, read double values and print the sum. If the Code
value is 2, read the integers and print the product. If the code
value is 3, read the strings and join them.

Sample Input: 1, 24.50, 67.00


Sample Output: 91.5
Sample Input: 3, ‘Hello’, ‘World’
Sample Output: HelloWorld
21 Once a baby lion lost his way in the jungle. An old deer took pity Medium
on him and planned to take him to his place. But the other deer
and his other friends — rabbits, squirrels, and birds are scared
so they accompanied. In the morning they counted themselves
to see if the baby lion done any mischief. Help them to find it.
Total number of animals, count of each (rabbit, deer, birds, and
squirrels) in the morning are the inputs.

Sample Input: 240, 27,48,124,38


Sample Output: Baby lion is mischievous
Sample Input: 250, 42,46,115,47
Sample Output: Baby lion is well
behaved
Sample Input: 120, 45,38,30, 27
Sample Output: Counted wrongly
22 A store charges $12 per item if you buy less than 10 items. If Medium
you buy between 10 and 99 items, the cost is $10 per item. If
you buy 100 or more items, the cost is $7 per item. Write the
logic that asks customer name, how many items they are buying
and prints the customer’s name and total cost.

Sample Input: Smith, 40


Sample Output: Smith 400
Sample Input: Eve, 111
Sample Output: Eve 777

It is going to be hard but, hard does not mean impossible.


6
HANDS-ON
SDE Readiness Training
23 Write a program to read a Coordinate Point in a XY Coordinate Medium
System and Determine its Quadrant.

Sample Input: 2 2
Sample Output: 1
24 Write a program to read a number N. Find the sum of odd and Medium
even numbers from 1 to N numbers (inclusive).

Sample Input: 10
Sample Output: 25 30
Sample Input: 15
Sample Output: 64 56
25 Reina and Sierra were playing a game. Reina would give out Medium
number, and Sierra must reverse the given number. Help Sierra
by writing program to reverse the number. Note that Reina
should give a five-digit number.

Sample Input: 61987


Sample Output: 78916
Sample Input: 1234
Sample Output: ‘Not a valid number’
26 Write a program to check whether the given number is prime or Medium
not.

Sample Input: 91
Sample Output: No
Sample Input: 97
Sample Output: Yes
27 Write a program to print all prime numbers between 1 and Medium
N(inclusive). N will be the input.

Sample Input: 5
Sample Output: 2 3 5
28 A student will not be allowed to sit in exam if his/her attendance Hard
is less than 75%. Number of classes held, and the Number of
classes attended are the inputs. Display the attendance
percentage and the eligibility of the student for the exam. Allow

It is going to be hard but, hard does not mean impossible.


7
HANDS-ON
SDE Readiness Training
the student to sit if he/she has medical cause. Ask user if he/she
has medical cause or not ( 'Y' or 'N' ) only when the attendance
is lacking and print accordingly.

Sample Input: 100, 80


Sample Output: 80% Allowed
Sample Input: 100, 60, ‘N’
Sample Output: 60% Not allowed
Sample Input: 100, 70, ‘Y’
Sample Output: 70% Allowed
29 Jessica teaches her students about how many days in a month, Hard
what is a leap year and how to find it. Write a program to help
her by saying the answer (number of days in a month) to expect
from the student for the given month number and the year.

Sample Input: 2, 2016


Sample Output: February 2016 has 29 days
Sample Input: 7, 2020
Sample Output: July 2020 has 31 days
Sample Input: 2, 2019
Sample Output: February 2019 has 28 days
30 Riya's teacher has asked her to prepare well for the lesson on Hard
seasons. When her teacher tells a month, she needs to say the
season corresponding to that month. Write a program to solve
the above task. Spring - March to May, Summer - June to
August, Autumn - September to November and, Winter -
December to February. Month should be in the range 1 to 12. If
not, the output should be "Invalid month".

Sample Input: 11
Sample Output: Autumn
Sample Input: 13
Sample Output: Invalid month

It is going to be hard but, hard does not mean impossible.


8

You might also like