# Number pattern 18 in C

Write a C program to print the given number pattern using loop. How to print the given number pattern of m rows and n columns using for loop in C programming. Logic to print the given number pattern using for loop in C program.

Example

Input

`Input N: 5`

Output

## Logic to print the given number pattern

Before learning the logic of this number pattern, you first must be acquainted with some basic number patterns.

Now, once you are acquainted with some basic logic to print number pattern. If you look to both the patterns you will find both similar to each other. Hence, if you get the logic of one you can easily print the second one. Now lets get into first pattern, take a minute and have a close eye to the below pattern.

If you can notice, you can actually divide this in two parts to make things easier. Let me show.

Now you can find that printing these patterns separately is relatively easier than the whole. Below is the logic to print this pattern as a whole.

1. To iterate through the rows, run an outer loop from 1 to N.
2. To print the first part of the pattern, run an inner loop from current_row to 1. Inside this loop print the current column number.
3. To print the second part of the pattern, run another inner loop from 1 to N-i + 1. Inside this loop print the value of current column number.

And you are done. Lets implement this on code.

Note: I won’t be explaining the logic of second pattern as both are similar in-fact second pattern is reverse of first.

## Program to print the given number pattern 1

``````/**
* C program to print number pattern
*/

#include <stdio.h>

int main()
{
int N, i, j;

printf("Enter N: ");
scanf("%d", &N);

for(i=1; i<=N; i++)
{
// Print first part
for(j=i; j>1; j--)
{
printf("%d", j);
}

// Print second part
for(j=1; j<= (N-i +1); j++)
{
printf("%d", j);
}

printf("\n");
}

return 0;
}``````

Output

```Enter N: 5
12345
21234
32123
43212
54321```

## Program to print the given number pattern 2

``````/**
* C program to print number pattern
*/

#include <stdio.h>

int main()
{
int N, i, j;

printf("Enter N: ");
scanf("%d", &N);

for(i=1; i<=N; i++)
{
// Print first part
for(j=(N-i +1); j>1; j--)
{
printf("%d", j);
}

// Print second part
for(j=1; j<=i; j++)
{
printf("%d", j);
}

printf("\n");
}

return 0;
}``````

Happy coding 😉
{"ft_lang_label":"__label__en","ft_lang_prob":0.66829,"math_prob":0.96231467,"size":2731,"snap":"2023-40-2023-50","text_gpt3_token_len":795,"char_repetition_ratio":0.17271727,"word_repetition_ratio":0.22222222,"special_character_ratio":0.3742219,"punctuation_ratio":0.12802768,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99578315,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-27T12:06:47Z\",\"WARC-Record-ID\":\"<urn:uuid:d67d63f5-49a8-4923-accb-1438aa57beee>\",\"Content-Length\":\"124926\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:059c5175-40cb-4027-a35a-0e82a7fa83bd>\",\"WARC-Concurrent-To\":\"<urn:uuid:d3795bf8-c5e8-4988-8ae9-4c509c485c10>\",\"WARC-IP-Address\":\"160.153.137.184\",\"WARC-Target-URI\":\"https://codeforwin.org/c-programming/number-pattern-18-in-c\",\"WARC-Payload-Digest\":\"sha1:KR6E2736THVD7OYIXJOCHPABPBV6GRXK\",\"WARC-Block-Digest\":\"sha1:FZFY4JX5KNNSOJ6W3OO6B2URD2A7GR7E\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233510297.25_warc_CC-MAIN-20230927103312-20230927133312-00245.warc.gz\"}"}