Advertisement
dmilicev

number_pattern_3.c

Nov 29th, 2023 (edited)
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. /*
  2.  
  3.     number_pattern_3.c
  4.  
  5. https://www.facebook.com/699199285504086/photos/gm.7403677166327822/705600451530636/
  6.  
  7. Square matrix with n=6 rows and columns.
  8. It starts with the number 1 and increases in each column by the row number.
  9. Each next row starts with the number that was the last in the previous row.
  10.  
  11.  1   2   3   4   5   6
  12.  
  13.  6   8  10  12  14  16
  14.  
  15. 16  19  22  25  28  31
  16.  
  17. 31  35  39  43  47  51
  18.  
  19. 51  56  61  66  71  76
  20.  
  21. 76  82  88  94 100 106
  22.  
  23.  
  24.  
  25.     You can find all my C programs at Dragan Milicev's pastebin:
  26.  
  27.     https://pastebin.com/u/dmilicev
  28.  
  29. */
  30.  
  31. #include <stdio.h>
  32.  
  33. int main(void){
  34.     int r, c, num=0, n=6;           // Square matrix with n=6 rows and columns.
  35.  
  36.     for(r=1;r<=n;r++){              // for all rows r
  37.         for(c=0;c<n;c++)            // for all columns c
  38.             printf("%4d",num+=r);   // num increases in each column by the row number
  39.         num-=r+1;   // Each next row starts with the number that was the last in the previous row.
  40.         printf("\n\n");             // space between rows
  41.     }
  42.  
  43.     return 0;
  44. } // main()
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement