0% found this document useful (0 votes)
13 views16 pages

Sri Krishna-Control Statements

Uploaded by

727722euec153
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)
13 views16 pages

Sri Krishna-Control Statements

Uploaded by

727722euec153
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/ 16

1.

Reverse the number using for loop

Example 1
Input
512

Output
215
2.Write a program that takes two integer limits, lower limit
(n1)and upper limit (n2), and prints the count of palindrome
numbers between these two limits (inclusive).

Sample Input:

n1-10
n2-100

Sample Output:
9
3.Find the factorial of a Number using do-while loop

Example 1
Input
5

Output
120
4.Write a program to print the hollow square pattern.

Sample Input 0
5

Sample Output 0
*****
* *
* *
* *
* ****
5.Write a program to generate the following series 0,2,8,14,...,34.

Sample Input 0
10

Sample Output 0
0 2 8 14 24 34 48 62 80 98

Sample Input 1
4
Sample Output 1
0 2 8 14
6.A number can be said as a strong number when the sum of the
factorial of the individual digits is equal to the number.
For example, 145 is a strong number. 1! + 4! + 5! = 145. Write a
program to check whether a given number is a strong number or not.

Sample Input 0
145

Sample Output 0
Yes

Explanation 0
= 1! + 4! +5! = 1+24+120 = 145
7.Find the sum of till single digit

Example 1
Input

5257

Output
19
8.Write a program to print the trapezium pattern.

Sample Input 0
4
Sample Output 0
1*2*3*4*17*18*19*20
--5*6*7*14*15*16
----8*9*12*13
------10*11
Sample Input 1
2
Sample Output 1
1*2*5*6
--3*4
9.Given N Rupees. A liter plastic bottle of milk costs R1
Rupees and a liter of the glass bottle of milk costs R2
Rupees. But the empty glass bottle after buying can be
exchanged for R3 Rupees. Find the maximum liters of milk
which can be bought with N Rupees (either plastic or glass
milk).

Example-1:

Input:
10 →Value of N
11 →Value of R1 i.e. price of plastic bottle
9→Value of R2 i.e. price of glass bottle
8 →Value of R3 i.e. price of empty glass bottle

Output:
10.Sum of till Single digit

Example-1:

Input:
99→Value of N
3 →Value of R

Output:
9

Explanation: Here, the number N=99 Sum of the digits N:


9+9 = 18 Repeat step 2 ‘R’ times i.e. 3 times
(9+9)+(9+9)+(9+9) = 18+18+18 =54 Add digits of 54 as
we need a single digit 5+4 Hence , the output is 9.
11.Given a number N, the task is to split the Num into
multiple parts in such a fashion as to find the highest
product.
Print the highest product value.
Consider N = 4.
Best: 4 = 2 + 2 and 2 * 2 = 4
Similarly for N = 6, (3 * 3) = 9
For N = 8, (2 * 3 * 3) = 18
For N = 15, (3 * 3 * 3 * 3 * 3) = 243
Constraints
1 <= N <= 100
Input format
The candidate has to write the code to accept a non-
negative integer number only.
Output format
The output should be a positive integer only.
Example 1
Input
4
Output
4
Example 2

Input Output
9 27
12.(Consider an n-digit number k. Square it and add the right n digits
to the left n or n-1 digits. If the resultant sum is k, then k is called a
Kaprekar number. For example, 9 is a Kaprekar number since 9^2 =
81 & 8 + 1 = 9, similarly, 297 is a Kaprekar number as 297^2 = 88209
& 88 + 209 = 297 ).

Sample Input 0
45
Sample Output 0
Kaprekar Number

Sample Input 1
23
Sample Output 1
Not a Kaprekar Number
13.Penny wanted to complete her graduation from the Community College
of California. But being the newbee she is , she does not how to multiply
two numbers. Sheldon being a good friend wanted to help Penny by writing
a program to print the multiplication table of an integer n.

Sample Input 0

N=5, m= 4
Sample Output 0

The multiplication table of 5 is


1*5=5
2*5=10
3*5=15
4*5=20
14. In the kingdom of Terebinthia, Leslie Burke is so much interested in
gardening and hence she plants more trees in her garden. She plants trees
in a rectangular fashion with the order of rows and columns and numbers
the trees in a row-wise order. She planted the mango trees only in the 1st
row, 1st column, and last column. So, given the tree number, your task is to
find out whether the given tree is a mango tree or not. Now, write a
program to check whether the given number denotes a mango tree or not.

Sample Input 0
5
5
11
Sample Output 0
Yes
15. Chander started working for Bing and he wanted him to write a
program to generate Collatz Sequence. The rules for generating the Collatz
sequence are: If n is even, n = n / 2. If n is odd, n = 3n + 1.
For example, if the starting number is 5 the sequence is: 5 -> 16 -> 8 -> 4 ->
2 -> 1 It has been proved for almost all integers, that the repeated
application of the above rule will result in a sequence that ends in 1.

Sample Input 0
18

Sample Output 0
18 9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 20

You might also like