**Example:**

Input N: 5

Output:

### Required knowledge

Basic C programming, If else, Loop### Logic to print the given number pattern

Logic to this pattern can be little tricky on first look. The pattern contains N rows (where N is the total number of rows to be printed). There are exactly i columns per row (where i is the current row number). Now, when you look to the pattern carefully you will find that the pattern contains odd and even columns.

If you don't know how to check even or odd, it is recommended that learn the logic of checking even or odd before continuing to this pattern.

When the row number is odd then the columns are odd, starting from first odd number and when it is even then the columns are even, starting from the first even number. For printing the numbers we will use an extra variable say k that will keep track of next number to be printed.Step-by-step-descriptive logic:

- To iterate through rows, run an outer loop from 1 to N.
- Inside this loop initialize a variable k = 1 if the current row is odd otherwise k = 2.
- To iterate through columns, run an inner loop from 1 to i (where i is current row number).

Inside this loop print the value of k and increment k = k + 2 to get the next even or odd number.

### Program to print the given number pattern

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

1

24

135

2468

13579

### Screenshot

Happy coding ;)

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