Hollow Right Triangle - 2
Given an integer number N as input. Write a program to print the hollow right-angled triangular pattern of N lines as shown below.
Note: There is a space after each asterisk (*) character.
Input
The first line of input is an integer N.
Explanation
In the given example the hollow right angled triangle of side
5. Therefore, the output should be
*
* *
* *
* *
* * * * *
Sample Input 1
4
Sample Output 1
*
* *
* *
* * * *
Sample Input 2
5
Sample Output 2
*
* *
* *
* *
* * * * *
Hollow Right Triangle
Given an integer number N as input. Write a program to print the hollow right-angled triangular pattern of N lines as shown below.
Note: There is a space after each asterisk (*) character.
Input
The first line of input is an integer N.
Explanation
In the given example the hollow right angled triangle of side
4. Therefore, the output should be
* * * *
* *
* *
*
Sample Input 1
4
Sample Output 1
* * * *
* *
* *
*
Sample Input 2
6
Sample Output 2
* * * * * *
* *
* *
* *
* *
*
Perfect Squares in a Range
You are given two given numbers, A and B where 1 <= A <= B, Write a program to find the number of perfect squares in the range A to B (including A and B).
Input
The first line of input is an integer A. The second line of input is an integer B.
Explanation
In the given example,
A = 9 and B = 100. The perfect squares in the range A to B are
3 * 3 = 9
4 * 4 = 16
5 * 5 = 25
6 * 6 = 36
7 * 7 = 49
8 * 8 = 64
9 * 9 = 81
10 * 10 = 100
So, the output should be
8.
Sample Input 1
9
100
Sample Output 1
8
Sample Input 2
625
1444
Sample Output 2
14
In the shop there are 3 barbers, Alpha, Beta and Gamma, who are not always efficient as employees. All the customers are seated in a waiting area, each customer has a card which has a unique integral ID.Alpha: He will call either the person with least ID from the waiting area of the one with max ID. Min or Max is decided randomly by him (assume 50% probability for each min or max). Beta: He will choose a ‘k’ and will call the kth smallest ID, (Kth ID when all IDs are arranged in ascending order). K is chosen randomly from the number of persons available in waiting area (1<= K <= Total persons)
Gamma: He will always choose the median ID. If there are ‘n’ people in the waiting area, the median will be defined as (n+1)/2 th ID when all of them are arranged in ascending order. (For both odd and even ‘n’ ). design a data structure which should support the query of each of the three barbers.
Shaded Diamond Given an integer value N as input,write a program to print a shaded diamond of 2*N -1 rows using an asterisk(*) character as shown below.
Sample Input 1
6
Sample Output 1
*
* *
* * *
* * * *
* * * * *
* * * * * *
* *
* *
* *
* *
*
Sample Input 2
5
Sample Output 2
*
* *
* * *
* * * *
* * * * *
* *
* *
* *
*
this code not correct output:
N = int(input())
for i in range(1, N + 1):
for j in range(1, N - i + 1):
print(end = ' ')
for l in range(1, 2 * i):
if l == 1 or l == i * 2 - 1:
print('*', end = '')
else:
print('*', end = '')
print()
for i in range(N - 1, 0, -1):
for j in range(1, N - i + 1):
print(' ', end = '')
for l in range(1, 2 * i):
print()Perfect Squares in a Range
You are given two given numbers, A and B where 1 <= A <= B, Write a program to find the number of perfect squares in the range A to B (including A and B).
Input
The first line of input is an integer A. The second line of input is an integer B.
Explanation
In the given example,
A = 9 and B = 100. The perfect squares in the range A to B are
3 * 3 = 9
4 * 4 = 16
5 * 5 = 25
6 * 6 = 36
7 * 7 = 49
8 * 8 = 64
9 * 9 = 81
10 * 10 = 100
So, the output should be
8.
Sample Input 1
9
100
Sample Output 1
8
Sample Input 2
625
1444
Sample Output 2
14
Sum of 1 series
Given integer N as input. Write a program to print the sum of series 1 + 11 + 111 + .... N terms.
Input
The first line of input is an integer N.
Output
The output should be an integer representing the sum of series.
Given
N = 4The sum for first
4 terms is 1 + 11 + 111 + 1111So the output should be
1234.
Sample Input 1
4
Sample Output 1
1234
Sample Input 2
5
Sample Output 2
12345
Number of digits until N
Given an integer N, write a program that prints the count of the total number of digits between 1 and N.
Input
The input is a positive integer.
The output should be a single line containing the count of the digits up to the given number.
Given
N = 10From 1 to 9, each number contains a single digit. From 10 onwards, the numbers contain two digits.
So the output should be 9 + 2 =
11.
Sample Input 1
10
Sample Output 1
11
Sample Input 2
4
Sample Output 2
4
Sum of K powers
Write a program to print the sum of the Kth power of the first N natural numbers.
Input
The first line of input is an integer N. The second line of input is an integer K.
Explanation
In the given example, the sum of first
5 natural numbers power of 3.The sum should be 13 + 23 + 33 + 43 + 53
Therefore, the output should be
225.
Sample Input 1
5
3
Sample Output 1
225
Sample Input 2
2
8
Sample Output 2
257