Knowee
Questions
Features
Study Tools

Write a program to print the following pattern if a number of rows are entered by the user at run time : For Example: if the number of rows is 51 2 6 3 7 10 4 8 11 13 5 9 12 14 15 Sample Test CasesTest Case 1:Expected Output:Enter·the·number·of·rows:·71·2·8·3·9·14·4·10·15·19·5·11·16·20·23·6·12·17·21·24·26·7·13·18·22·25·27·28·Test Case 2:Expected Output:Enter·the·number·of·rows:·51·2·6·3·7·10·4·8·11·13·5·9·12·14·15·

Question

Write a program to print the following pattern if a number of rows are entered by the user at run time : For Example: if the number of rows is 51 2 6 3 7 10 4 8 11 13 5 9 12 14 15 Sample Test CasesTest Case 1:Expected Output:Enter·the·number·of·rows:·71·2·8·3·9·14·4·10·15·19·5·11·16·20·23·6·12·17·21·24·26·7·13·18·22·25·27·28·Test Case 2:Expected Output:Enter·the·number·of·rows:·51·2·6·3·7·10·4·8·11·13·5·9·12·14·15·

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a Python program that will print the pattern as per your requirement:

def print_pattern(n):
    count = 1
    for i in range(1, n+1):
        temp = i
        for j in range(i):
            print(temp, end=' ')
            temp += n - j
        print()
        count += 1

# Test Case 1
print("Enter the number of rows: 7")
print_pattern(7)

# Test Case 2
print("Enter the number of rows: 5")
print_pattern(5)

In this program, we define a function print_pattern(n) that takes an integer n as input and prints the desired pattern. The outer loop runs n times, and the inner loop runs i times where i is the current iteration of the outer loop. The variable temp is used to print the numbers in the pattern. It starts with the value of i and is incremented by n - j in each iteration of the inner loop, where j is the current iteration of the inner loop. The end=' ' argument in the print function is used to print a space after each number instead of a newline. The print() statement after the inner loop is used to print a newline after each row of the pattern.

This problem has been solved

Similar Questions

Test time left: 02:44:35Print PatternWrite a program to print the following pattern if a number of rows are entered by the user at run time : For Example: if the number of rows is 51 2 6 3 7 10 4 8 11 13 5 9 12 14 15 Sample Test CasesTest Case 1:Expected Output:Enter·the·number·of·rows:·71·2·8·3·9·14·4·10·15·19·5·11·16·20·23·6·12·17·21·24·26·7·13·18·22·25·27·28·Test Case 2:Expected Output:Enter·the·number·of·rows:·51·2·6·3·7·10·4·8·11·13·5·9·12·14·15·

Develop a C program to print the following pattern of N rows using whileloop (Read N value from the Keyboard)For Example: N value : 512 34 5 67 8 9 1011 12 13 14

Write a C program to print the Pyramid with numbersWrite a program to print a pyramid of numbers separated by spaces for the given number of rows.At the time of execution, the program should print the message on the console as:Enter number of rows : For example, if the user gives the input as:Enter number of rows : 5then the program should print the result as:Enter number of rows : 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

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

Test Data : Input number of rows: 5 Expected Output : 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1

1/3

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.