Looping-4Read a integer N and print a character pattern with N rows.For example if N=5, the pattern isABBCCCDDDDE E E E E
Question
Looping-4
Read an integer N and print a character pattern with N rows.
For example, if N = 5, the pattern is:
A
BB
CCC
DDDD
E E E E
Solution
Sure, here is a Python solution for your problem:
def print_pattern(N):
for i in range(1, N+1):
print(str(chr(64 + i)) * i)
print_pattern(5)
This function works by looping from 1 to N (inclusive). For each iteration, it converts the current number to a character (using the ASCII value, where 'A' is 65) and then repeats that character i times.
For example, if N=5, the output will be:
A
BB
CCC
DDDD
EEEEE
This is because in the first iteration, 'A' is printed once. In the second iteration, 'B' is printed twice. In the third iteration, 'C' is printed three times, and so on.
Similar Questions
Read a integer N and print a character pattern with N rows.For example if N=5, the pattern isABBCCCDDDDEEEEE
The output of the code will be ____. int i=5; printf(“%d %d %d”, i, i++, ++i); ans.
Write a python code to get the given pattern without using ‘FOR’ loop. A minimum of six WHILE LOOPS must be used effectively to get the output.
Write a program to print the following output: [3] 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1
The output of the code will be ____. int i=5; printf(“%d %d %d”, i, i++, ++i); ans. 7 6 5 7 6 6 5 5 7 7 6 7
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.