Advertisement
dmilicev

number_pattern_v1.c

Jun 4th, 2020
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. /*
  2.  
  3.     number_pattern_v1.c
  4.  
  5.     12345
  6.     2345
  7.     345
  8.     45
  9.     5
  10.  
  11.  
  12.     You can find all my C programs at Dragan Milicev's pastebin:
  13.  
  14.     https://pastebin.com/u/dmilicev
  15.  
  16. */
  17.  
  18. #include <stdio.h>
  19.  
  20. void print_pattern_v1(int rows)
  21. {
  22.     int r,c,first_number=1; // r and c is for row and column
  23.  
  24.     for(r=0;r<rows;r++)
  25.     {
  26.         for(c=0;c<rows-r;c++)
  27.             printf("%d",first_number+c);
  28.  
  29.         first_number++;
  30.         printf("\n");
  31.     }
  32. }
  33.  
  34. void print_pattern_v2(int rows)
  35. {
  36.     int r,c;    // r and c is for row and column
  37.  
  38.     for(r=0;r<rows;r++)
  39.     {
  40.         for(c=0;c<rows-r;c++)
  41.             printf("%d",r+1+c);
  42.  
  43.         printf("\n");
  44.     }
  45. }
  46.  
  47. void print_pattern_v3(int rows)
  48. {
  49.     int r,c;    // r and c is for row and column
  50.  
  51.     for(r=0;r<rows;r++)
  52.     {
  53.         for(c=0;c<rows;c++)
  54.             if(c+1>r)
  55.                 printf("%d",c+1);
  56.  
  57.         printf("\n");
  58.     }
  59. }
  60.  
  61. void print_pattern_v4(int rows)
  62. {
  63.     int arr[]={1,2,3,4,5,6,7,8,9};
  64.     int r,c;    // r and c is for row and column
  65.  
  66.     if( rows<1 || rows>9 )
  67.     {
  68.         printf("\n Rows must be between 1 and 9 \n");
  69.         return;
  70.     }
  71.  
  72.     for(r=0;r<rows;r++)
  73.     {
  74.         for(c=0;c<rows;c++)
  75.             if(c+1>r)
  76.                 printf("%d",arr[c]);
  77.  
  78.         printf("\n");
  79.     }
  80. }
  81.  
  82.  
  83. int main(void)
  84. {
  85.     printf("\n Version 1: \n\n");
  86.     print_pattern_v1(5);
  87.  
  88.     printf("\n Version 2: \n\n");
  89.     print_pattern_v2(5);
  90.  
  91.     printf("\n Version 3: \n\n");
  92.     print_pattern_v3(5);
  93.  
  94.     printf("\n Version 4: \n\n");
  95.     print_pattern_v4(5);
  96.  
  97.  
  98.     return 0;
  99.  
  100. } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement