Example:
Input N: 5
Output:
Required knowledge
Basic C programming, LoopLogic to print the given number pattern
The above pattern might seem confusing at first go. But trust me solving this will definitely boost your logical and reasoning thinking ability. Take your time and observe the logic of the pattern. If its getting difficult to solve the pattern let me help you to solve the pattern. You can easily notice following things about the pattern.- It contains total N rows (where N is the total number of rows to be printed).
- Each row contains total i number of columns (where i is the current row number).
- Now when you look to the number of each row they are in special format. Number of each row starts with the current row number i.e. i. And they continue to increment in special format. The differences between columns are 4, 3, 2, 1. i.e. If the first term of column is 5 then next will be 5+4=9, 9+3=12, 12+2=14 and so on...
Program to print the given number pattern
/** * C program to print the given number pattern */ #include <stdio.h> int main() { int i, j, diff, value, N; printf("Enter rows: "); scanf("%d", &N); for(i=1; i<=N; i++) { diff = N-1; // Initialize difference to total rows - 1 value = i; // Initialize value to the current row number for(j=1; j<=i; j++) { printf("%-3d", value); value += diff; // Computes the next value to be printed diff--; // Decrements the difference } printf("\n"); } return 0; }
Output
Enter rows: 5
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
1
2 6
3 7 10
4 8 11 13
5 9 12 14 15
Screenshot
Happy coding ;)