bsc

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

root / semester_1 / tuition-c / P053.c

P053.c (2846B)


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