Write a C program to print the given number pattern using loop. How to print the given number pattern using for loop in C programming. Logic to print the given number pattern using loop in C program.

Input N: 5

Output:

To get the logic of above pattern just have a close eye on the pattern. Lets suppose that the rows starts from 1 to N (where N is the total rows to be printed). Then total columns per row is N - current_row_number + 1 i.e. first row contains 5 - 1 + 1 = 5 columns and so on. And for each column the current row number gets printed. Hence, the step by step descriptive logic to print the given logic is:

Happy coding ;)

**Example:**Input N: 5

Output:

### Required knowledge

Basic C Programming, Loop### Logic to print the given number pattern 1

To get the logic of above pattern just have a close eye on the pattern. Lets suppose that the rows starts from 1 to N (where N is the total rows to be printed). Then total columns per row is N - current_row_number + 1 i.e. first row contains 5 - 1 + 1 = 5 columns and so on. And for each column the current row number gets printed. Hence, the step by step descriptive logic to print the given logic is:

- To iterate through rows, start an outer loop from 1 to N.
- To print the numbers, start an inner loop from current row number to N. Inside this loop print the value of current row number.

### Program to print the given number pattern 1

/** * C program to print number pattern */ #include <stdio.h> int main() { int i, j, N; printf("Enter N: "); scanf("%d", &N); for(i=1; i<=N; i++) { //Logic to print numbers for(j=i; j<=N; j++) { printf("%d", i); } printf("\n"); } return 0; }

Output

Enter N: 5

11111

2222

333

44

5

11111

2222

333

44

5

### Screenshot 1

### Logic to print the given number pattern 2

Now, once you get the logic of printing the first number pattern you can easily print this pattern. As both are similar except that it contains extra trailing spaces. Hence you only need to add the logic of printing spaces before the number gets printed in the first number pattern. If you point your mouse over the pattern you can actually count total number of spaces per row and can get the logic in which spaces are printed. Now as you can see, each row contains row_number - 1 spaces. Logic to print spaces is-- To print spaces, run an inner loop from 1 to current_row_number - 1. Inside this loop print single blank space.

### Program to print given number pattern 2

/** * C program to print number pattern */ #include <stdio.h> int main() { int i, j, N; printf("Enter N: "); scanf("%d", &N); for(i=1; i<=N; i++) { //Logic to print spaces for(j=1; j<i; j++) { printf(" "); } //Logic to print numbers for(j=i; j<=N; j++) { printf("%d", i); } printf("\n"); } return 0; }

### Screenshot 2

Happy coding ;)

< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).