0% found this document useful (0 votes)
17 views18 pages

Day 1

Uploaded by

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

Day 1

Uploaded by

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

Competitive

Coding

C Language
Q1- Compute Area of Rectangle

Given the length and breadth of a rectangle, print area of the


rectangle.
Input Format
First and only line of input contains two positive integers L -
length of the rectangle and B - breadth of the rectangle.
Output Format
Print area of the given rectangle.
Sample Input Sample Output
58 40
Q2- Triangle Validator

Given the length of 3 sides of a triangle, check whether the triangle is valid or
not.
Input Format
First and only line of input contains three integers A, B, C - length of sides of
the triangle.
Output Format
Print "Yes" if you can construct a triangle with the given three sides, "No"
otherwise.
Sample Input-1 Sample Output-1
435 Yes
Sample Input-2 Sample Input-2
9 15 2 No
Q3- Number Reverse

Given a number N, reverse the number.


Input Format
First and only line of input contains a integer - N.
Output Format
Print the reversed number.
Sample Input Sample Output
1344 4431
Q4- Divide the Apples

n schoolchildren divide k apples evenly, the residue remains in the


basket. How many apples remains in the basket?
Input Format
Two integers n and k not greater than 1500 --- rarely happens in school more pupils, and
where to fi nd such a basket?
Output Format
Print the number of apples in the basket.
Sample Input-1 Sample Output-1
3 2
14
Sample Input-2 Sample Output-2
10 0
100
Q5- Watermelon

One hot summer day Pete and his friend Billy decided to buy a watermelon. They
chose the biggest and the ripest one, in their opinion. After that the watermelon
was weighed, and the scales showed w kilos. They rushed home, dying of thirst,
and decided to divide the berry, however they faced a hard problem.

Pete and Billy are great fans of even numbers, that's why they want to divide the
watermelon in such a way that each of the two parts weighs even number of
kilos, at the same time it is not obligatory that the parts are equal. The boys are
extremely tired and want to start their meal as soon as possible, that's why you
should help them and fi nd out, if they can divide the watermelon in the way they
want. For sure, each of them should get a part of positive weight.
Q5- Watermelon

Input Format
The first (and the only) input line contains integer number w
(1 ≤ w ≤ 100) — the weight of the watermelon bought by the
boys.
Output Format
Print YES, if the boys can divide the watermelon into two parts,
each of them weighing even number of kilos; and NO in the
opposite case.
Sample Input Sample Output
8 Yes
Note
For example, the boys can divide the watermelon into two parts of 2 and 6
kilos respectively (another variant — two parts of 4 and 4 kilos).
Q6- ATM

Pooja would like to withdraw x US from an ATM. The cash machine will only accept the
transaction x which is a multiple of 5, and Pooja’s account balance has enough cash
US.
Calculate Pooja’s account balance after an attempted transaction.
Input Format
Each input contains 2 integers X and Y.
X is the amount of cash which Pooja wishes to withdraw.
Y is Pooja's initial account balance.
Output Format
Output the account balance after the attempted transaction, given as a number with
two digits of precision. If there is not enough money in the account to complete the
transaction, output the current bank balance.
Q6- ATM

Sample Input-1 Sample Output-1


30 120.00 89.50
Example - Successful Transaction
Sample Input-2 Sample Output-2
42 120.00 120.00
Example - Incorrect Withdrawal Amount (not multiple of 5)
Sample Input-3 Sample Output-3
300 120.00 120.00
Example - Insuffi cient Funds
Q7- Discount

Alice buys a toy with a selling price of 100 rupees. There is a discount
of x percent on the toy. Find the amount Alice needs to pay for it.
Input Format
The first line of input will contain a single integer T, denoting the
number of test cases.
The first and only line of each test case contains a single integer, x —
the discount on the toy.
Output Format
For each test case, output on a new line the price that Alice needs to
pay.
Sample Input Sample Output
4
5 95
9 91
11 89
21 79
Note
The discount is 5 percent, i.e., 5 rupees. So, Alice will have to pay 100 – 5 = 95 rupees.
Q8- Sum or Difference

Write a program to take two numbers as input and print their


difference if the first number is greater than the second number
otherwise print their sum.
Input Format
First line will contain the first number (N1)
Second line will contain the second number (N2)
Output Format
Output a single line containing the difference of 2 numbers
(N1−N2) if the first number is greater than the second number
otherwise output their sum (N1+N2).
Sample Input Sample Output
82 28 54
Q9- Second Largest

Three numbers A, B and C are the inputs. Write a program to


find second largest among them.
Input Format
It contains three integers A, B and C.
Output Format
Display the second largest among A, B and C
Sample Input Sample Output
120 11 400 120
Q10- Lucky Four

You are given an integer, you have to calculate the number of


occurrences of the digit 4 in the decimal representation.
Input Format
It contains an integer n.
Output Format
It contain the number of occurrences of the digit 4 in the
respective integer.
Sample Input Sample Output
447474 4
Q11- Natural numbers sum

Given a positive integer N, print the sum of 1st N natural


numbers.
Input Format
First and only line of input contains a positive integer - N.
Output Format
Print the sum of 1st N natural numbers.
Sample Input Sample Output
4 10
Q12- Compute N!

Given a non-negative number - N, print N!


Input Format
First and only line of input contains a number - N.
Output Format
Print factorial of N.
Sample Input Sample Output
5 10
Q13- Sum of Digits

Find the sum of the first and the last digit in four-digit positive
integer.
Input Format
One four-digit positive integer.
Output Format
Print the sum of the first and the last digit.
Sample Input Sample Output
1235 6
Q14- Sum of Digits

Find the sum of the given digits.


Input Format
An Integer n.
Output Format
Print the sum of the digits.
Sample Input Sample Output
1235 11
Q15- Next Even integer

Integer n is given. Print the next even integer for n.


Input Format
One integer n.
Output Format
Print the next even integer after n.
Sample Input-1 Sample Output-1
7 8
Sample Input-2 Sample Input-2
4 6

You might also like