Knowee
Questions
Features
Study Tools

Read a integer N and print a character pattern with N rows.For example if N=5, the pattern isABBCCCDDDDEEEEE

Question

Read an integer N and print a character pattern with N rows.

For example, if N=5, the pattern is:

A
BB
CCC
DDDD
EEEEE
🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a Python solution for your problem:

def print_pattern(N):
    for i in range(1, N+1):
        print(chr(64 + i) * i)

print_pattern(5)

Here is how it works:

  1. We define a function print_pattern that takes an integer N as input.
  2. We start a loop that goes from 1 to N (inclusive).
  3. Inside the loop, we print a character that is determined by adding i to 64 and converting the result to a character (since the ASCII value of 'A' is 65), and we repeat this character i times.
  4. Finally, we call the function with the input 5.

When you run this code, it will print the pattern you described.

This problem has been solved

Similar Questions

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

The output of the code will be ____. int i=5; printf(“%d %d %d”, i, i++, ++i); ans.

Write a program to print the following output: [3] 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1

main( ){int i, j ;for ( i = 1 ; i <= 2 ; i++ ){for ( j = 1 ; j <= 2 ; j++ ){if ( i == j )continue ;printf ( “n%d %dn”, i, j ) ;}}}1 22 12 11 23 22 3Error

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.

1/1

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.