Sri Krishna-Control Statements
Sri Krishna-Control Statements
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
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
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