bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

P053.c (3037B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 12 Dec 2025
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /* Print all pattern */
      9 
     10 // This code has not been compiled.
     11 // If you find any issues, please create a new issue on GitHub regarding them.
     12 // Go to this link to create a new issue: https://github.com/notamitgamer/bsc/issues
     13 
     14 #include <stdio.h>
     15 
     16 int main()
     17 {
     18     int i, j, temp;
     19 
     20     printf("\n\nPattern 1 : \n\n");
     21     /*
     22     9   9   9   9   9
     23     7   7   7   7   7
     24     5   5   5   5   5
     25     3   3   3   3   3
     26     1   1   1   1   1
     27     */
     28     temp = 9;
     29     for (i = 1; i <= 5; i++)
     30     {
     31         for (j = 1; j <= 5; j++)
     32         {
     33             printf("%d  ", temp);
     34         }
     35         printf("\n");
     36         temp -= 2;
     37     }
     38 
     39     // Another method print above pattern
     40     printf("\n\nPattern 1 : \n\n");
     41     for (i = 9; i >= 1; i -= 2)
     42     {
     43         for (j = 1; j <= 5; j++)
     44         {
     45             printf("%d  ", i);
     46         }
     47         printf("\n");
     48     }
     49 
     50     printf("\n\nPattern 2 : \n\n");
     51     /*
     52     1   2   3   4   5
     53     1   2   3   4   5
     54     1   2   3   4   5
     55     */
     56     for (i = 1; i <= 3; i++)
     57     {
     58         for (j = 1; j <= 5; j++)
     59         {
     60             printf("%d  ", j);
     61         }
     62         printf("\n");
     63     }
     64 
     65     printf("\n\nPattern 3 : \n\n");
     66     /*
     67     5   4   3   2   1
     68     5   4   3   2   1
     69     */
     70     for (i = 1; i <= 2; i++)
     71     {
     72         for (j = 5; j >= 1; j--)
     73         {
     74             printf("%d  ", j);
     75         }
     76         printf("\n");
     77     }
     78 
     79     printf("\n\nPattern 4 : \n\n");
     80     /*
     81     1   2   3   4
     82     5   6   7   8
     83     9   10  11  12
     84     */
     85     temp = 1;
     86     for (i = 1; i <= 3; i++)
     87     {
     88         for (j = 1; j <= 4; j++)
     89         {
     90             printf("%d  ", temp);
     91             temp++;
     92         }
     93         printf("\n");
     94     }
     95 
     96     printf("\n\nPattern 5 : \n\n");
     97     /*
     98     1   2   3   4
     99     4   8   12  16
    100     1   2   3   4
    101     4   8   12  16
    102     1   2   3   4
    103     */
    104     for (i = 1; i <= 5; i++)
    105     {
    106         for (j = 1; j <= 4; j++)
    107         {
    108             if (i % 2 == 0)
    109                 printf("%d  ", j * 4);
    110             else
    111                 printf("%d  ", j);
    112         }
    113         printf("\n");
    114     }
    115 
    116     printf("\n\nPattern 6 : \n\n");
    117     /*
    118     1
    119     2   4
    120     3   5   7
    121     6   8   10  12
    122     9   11  13  15  17
    123     */
    124     int odd = 1, even = 2;
    125     for (i = 1; i <= 5; i++)
    126     {
    127         for (j = 1; j <= i; j++)
    128         {
    129             if (i % 2 == 0)
    130             {
    131                 printf("%d  ", even);
    132                 even += 2;
    133             }
    134             else
    135             {
    136                 printf("%d  ", odd);
    137                 odd += 2;
    138             }
    139         }
    140         printf("\n");
    141     }
    142 
    143     printf("\n\nPattern 7 : \n\n");
    144     /*
    145     1   2   3   4   5
    146     6   7   8   9
    147     10  11  12
    148     13  14
    149     15
    150     */
    151     temp = 1;
    152     for (i = 5; i >= 1; i--)
    153     {
    154         for (j = 1; j <= i; j++)
    155         {
    156             printf("%d  ", temp);
    157             temp++;
    158         }
    159         printf("\n");
    160     }
    161 
    162     return 0;
    163 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror