Advertisement
dmilicev

C_number_paterns.c

Oct 9th, 2023 (edited)
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.64 KB | None | 0 0
  1. /*
  2.  
  3.     C_number_paterns.c
  4.  
  5. https://www.facebook.com/groups/3092811364081112/?multi_permalinks=7191234904238717
  6.  
  7.     You can find all my C programs at Dragan Milicev's pastebin:
  8.  
  9.     https://pastebin.com/u/dmilicev
  10.  
  11. */
  12.  
  13. #include <stdio.h>
  14.  
  15. int main(void){
  16. // r - row, c - column, b - blanco, d - digit, n - number of rows
  17.     int i, j, r, c, b, d, n=5;
  18.  
  19. /*
  20. 1
  21. 1 1
  22. 1 1 1
  23. 1 1 1 1
  24. 1 1 1 1 1
  25. */
  26.     printf("\n   1.0 \n\n");
  27.     for(r=0;r<n;r++){           // for n rows
  28.         for(c=0;c<=r;c++)       // count columns
  29.             printf("1 ");       // print pattern
  30.         printf("\n");           // new row
  31.     }
  32.  
  33. /*
  34. 1
  35. 2 2
  36. 3 3 3
  37. 4 4 4 4
  38. 5 5 5 5 5
  39. */
  40.     printf("\n   1.1 \n\n");
  41.     for(r=0;r<n;r++){           // for n rows
  42.         for(c=0;c<=r;c++)       // count columns
  43.             printf("%d ",r+1);  // print pattern
  44.         printf("\n");           // new row
  45.     }
  46.  
  47.     /*
  48. 5
  49. 4 4
  50. 3 3 3
  51. 2 2 2 2
  52. 1 1 1 1 1
  53. */
  54.     printf("\n   1.2 \n\n");
  55.     for(r=0;r<n;r++){           // for n rows
  56.         for(c=0;c<=r;c++)       // count columns
  57.             printf("%d ",n-r);  // print pattern
  58.         printf("\n");           // new row
  59.     }
  60.  
  61. /*
  62. 1
  63. 1 2
  64. 1 2 3
  65. 1 2 3 4
  66. 1 2 3 4 5
  67. */
  68.     printf("\n   1.3 \n\n");
  69.     for(r=0;r<n;r++){           // for n rows
  70.         for(c=0;c<=r;c++)       // count columns
  71.             printf("%d ",c+1);  // print pattern
  72.         printf("\n");           // new row
  73.     }
  74.  
  75. /*
  76. 1
  77. 2 1
  78. 3 2 1
  79. 4 3 2 1
  80. 5 4 3 2 1
  81. */
  82.     printf("\n   1.4 \n\n");
  83.     for(r=0;r<n;r++){           // for n rows
  84.         d = r+1;                // first digit in row
  85.         for(c=0;c<=r;c++)       // count columns
  86.             printf("%d ", d--); // print pattern
  87.         printf("\n");           // new row
  88.     }
  89.  
  90. /*
  91. 5
  92. 4 5
  93. 3 4 5
  94. 2 3 4 5
  95. 1 2 3 4 5
  96. */
  97.     printf("\n   1.5 \n\n");
  98.     for(r=0;r<n;r++){           // for n rows
  99.         d = n-r;                // first digit in row
  100.         for(c=0;c<=r;c++)       // count columns
  101.             printf("%d ", d++); // print pattern
  102.         printf("\n");           // new row
  103.     }
  104.  
  105. /*
  106. 1
  107. 2 3
  108. 4 5 6
  109. 7 8 9 10
  110. 11 12 13 14 15
  111. */
  112.     printf("\n   1.6 \n\n");
  113.     d = 1;                      // first digit
  114.     for(r=0;r<n;r++){           // for n rows
  115.         for(c=0;c<=r;c++)       // count columns
  116.             printf("%d ", d++); // print pattern
  117.         printf("\n");           // new row
  118.     }
  119.  
  120. /*
  121.         1
  122.       1 1
  123.     1 1 1
  124.   1 1 1 1
  125. 1 1 1 1 1
  126. */
  127.     printf("\n   2.0 \n\n");
  128.     for(r=0;r<n;r++){           // for n rows
  129.         for(b=n-r-1;b>0;b--)    // count blanko
  130.             printf("  ");       // print blanko
  131.         for(c=0;c<=r;c++)       // count columns
  132.             printf("1 ");       // print pattern
  133.         printf("\n");           // new row
  134.     }
  135.  
  136. /*
  137.         1
  138.       1 2
  139.     1 2 3
  140.   1 2 3 4
  141. 1 2 3 4 5
  142. */
  143.     printf("\n   2.1 \n\n");
  144.     for(r=0;r<n;r++){           // for n rows
  145.         for(b=n-r-1;b>0;b--)    // count blanko
  146.             printf("  ");       // print blanko
  147.         d = 1;                  // first digit in row
  148.         for(c=0;c<=r;c++)       // count columns
  149.             printf("%d ",d++);  // print pattern
  150.         printf("\n");           // new row
  151.     }
  152.  
  153. /*
  154.         5
  155.       5 4
  156.     5 4 3
  157.   5 4 3 2
  158. 5 4 3 2 1
  159. */
  160.     printf("\n   2.2 \n\n");
  161.     for(r=0;r<n;r++){           // for n rows
  162.         for(b=n-r-1;b>0;b--)    // count blanko
  163.             printf("  ");       // print blanko
  164.         d = n;                  // first digit in row
  165.         for(c=0;c<=r;c++)       // count columns
  166.             printf("%d ",d--);  // print pattern
  167.         printf("\n");           // new row
  168.     }
  169.  
  170. /*
  171. 1 1 1 1 1
  172.   1 1 1 1
  173.     1 1 1
  174.       1 1
  175.         1
  176. */
  177.     printf("\n   3.0 \n\n");
  178.     for(r=0;r<n;r++){           // for n rows
  179.         for(b=0;b<r;b++)        // count blanko
  180.             printf("  ");       // print blanko
  181.         for(c=0;c<n-r;c++)      // count columns
  182.             printf("1 ");       // print pattern
  183.         printf("\n");           // new row
  184.     }
  185.  
  186. /*
  187. 1 2 3 4 5
  188.   1 2 3 4
  189.     1 2 3
  190.       1 2
  191.         1
  192. */
  193.     printf("\n   3.1 \n\n");
  194.     for(r=0;r<n;r++){           // for n rows
  195.         for(b=0;b<r;b++)        // count blanko
  196.             printf("  ");       // print blanko
  197.         d = 1;                  // first digit in row
  198.         for(c=0;c<n-r;c++)      // count columns
  199.             printf("%d ",d++);      // print pattern
  200.         printf("\n");           // new row
  201.     }
  202.  
  203. /*
  204. 5 4 3 2 1
  205.   5 4 3 2
  206.     5 4 3
  207.       5 4
  208.         5
  209. */
  210.     printf("\n   3.2 \n\n");
  211.     for(r=0;r<n;r++){           // for n rows
  212.         for(b=0;b<r;b++)        // count blanko
  213.             printf("  ");       // print blanko
  214.         d = n;                  // first digit in row
  215.         for(c=0;c<n-r;c++)      // count columns
  216.             printf("%d ",d--);  // print pattern
  217.         printf("\n");           // new row
  218.     }
  219.  
  220. /*
  221. 1 1 1 1 1
  222. 1 1 1 1
  223. 1 1 1
  224. 1 1
  225. 1
  226. */
  227.     printf("\n   4.0 \n\n");
  228.     for(r=0;r<n;r++){           // for n rows
  229.         for(c=n-r;c>0;c--)      // count columns
  230.             printf("1 ");       // print pattern
  231.         printf("\n");           // new row
  232.     }
  233.  
  234. /*
  235. 1 2 3 4 5
  236. 2 3 4 5
  237. 3 4 5
  238. 4 5
  239. 5
  240. */
  241.     printf("\n   4.1 \n\n");
  242.     for(r=0;r<n;r++){           // for n rows
  243.         d = r + 1;              // first digit in row
  244.         for(c=n-r;c>0;c--)      // count columns
  245.             printf("%d ",d++);  // print pattern
  246.         printf("\n");           // new row
  247.     }
  248.  
  249. /*
  250. 5 4 3 2 1
  251. 4 3 2 1
  252. 3 2 1
  253. 2 1
  254. 1
  255. */
  256.     printf("\n   4.2 \n\n");
  257.     for(r=0;r<n;r++){           // for n rows
  258.         d = n - r;              // first digit in row
  259.         for(c=n-r;c>0;c--)      // count columns
  260.             printf("%d ",d--);  // print pattern
  261.         printf("\n");           // new row
  262.     }
  263.  
  264. /*
  265.     1
  266.    1 1
  267.   1 1 1
  268.  1 1 1 1
  269. 1 1 1 1 1
  270. */
  271.     printf("\n   5.0 \n\n");
  272.     for(r=0;r<n;r++){           // for n rows
  273.         for(b=n-r-1;b>0;b--)    // count blanko
  274.             printf(" ");        // print blanko
  275.         for(c=0;c<=r;c++)       // count columns
  276.             printf("1 ");       // print pattern
  277.         printf("\n");           // new row
  278.     }
  279.  
  280. /*
  281.     1
  282.    1 2
  283.   1 2 3
  284.  1 2 3 4
  285. 1 2 3 4 5
  286. */
  287.     printf("\n   5.1 \n\n");
  288.     for(r=0;r<n;r++){           // for n rows
  289.         for(b=n-r-1;b>0;b--)    // count blanko
  290.             printf(" ");        // print blanko
  291.         d = 1;                  // first digit in row
  292.         for(c=0;c<=r;c++)       // count columns
  293.             printf("%d ",d++);  // print pattern
  294.         printf("\n");           // new row
  295.     }
  296.  
  297. /*
  298.     5
  299.    5 4
  300.   5 4 3
  301.  5 4 3 2
  302. 5 4 3 2 1
  303. */
  304.     printf("\n   5.2 \n\n");
  305.     for(r=0;r<n;r++){           // for n rows
  306.         for(b=n-r-1;b>0;b--)    // count blanko
  307.             printf(" ");        // print blanko
  308.         d = n;                  // first digit in row
  309.         for(c=0;c<=r;c++)       // count columns
  310.             printf("%d ",d--);  // print pattern
  311.         printf("\n");           // new row
  312.     }
  313.  
  314. /*
  315. 1 1 1 1 1
  316.  1 1 1 1
  317.   1 1 1
  318.    1 1
  319.     1
  320. */
  321.     printf("\n   6.0 \n\n");
  322.     for(r=0;r<n;r++){           // for n rows
  323.         for(b=0;b<r;b++)        // count blanko
  324.             printf(" ");        // print blanko
  325.         for(c=0;c<n-r;c++)      // count columns
  326.             printf("1 ");       // print pattern
  327.         printf("\n");           // new row
  328.     }
  329.  
  330. /*
  331. 1 2 3 4 5
  332.  1 2 3 4
  333.   1 2 3
  334.    1 2
  335.     1
  336. */
  337.     printf("\n   6.1 \n\n");
  338.     for(r=0;r<n;r++){           // for n rows
  339.         for(b=0;b<r;b++)        // count blanko
  340.             printf(" ");        // print blanko
  341.         d = 1;                  // first digit in row
  342.         for(c=0;c<n-r;c++)      // count columns
  343.             printf("%d ",d++);  // print pattern
  344.         printf("\n");           // new row
  345.     }
  346.  
  347. /*
  348. 5 4 3 2 1
  349.  5 4 3 2
  350.   5 4 3
  351.    5 5
  352.     5
  353. */
  354.     printf("\n   6.2 \n\n");
  355.     for(r=0;r<n;r++){           // for n rows
  356.         for(b=0;b<r;b++)        // count blanko
  357.             printf(" ");        // print blanko
  358.         d = n;                  // first digit in row
  359.         for(c=0;c<n-r;c++)      // count columns
  360.             printf("%d ",d--);  // print pattern
  361.         printf("\n");           // new row
  362.     }
  363.  
  364.  
  365.  
  366.     printf("\n\n");
  367.     return 0;
  368. } // main()
  369.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement