Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- C_number_paterns.c
- https://www.facebook.com/groups/3092811364081112/?multi_permalinks=7191234904238717
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- int main(void){
- // r - row, c - column, b - blanco, d - digit, n - number of rows
- int i, j, r, c, b, d, n=5;
- /*
- 1
- 1 1
- 1 1 1
- 1 1 1 1
- 1 1 1 1 1
- */
- printf("\n 1.0 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(c=0;c<=r;c++) // count columns
- printf("1 "); // print pattern
- printf("\n"); // new row
- }
- /*
- 1
- 2 2
- 3 3 3
- 4 4 4 4
- 5 5 5 5 5
- */
- printf("\n 1.1 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(c=0;c<=r;c++) // count columns
- printf("%d ",r+1); // print pattern
- printf("\n"); // new row
- }
- /*
- 5
- 4 4
- 3 3 3
- 2 2 2 2
- 1 1 1 1 1
- */
- printf("\n 1.2 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(c=0;c<=r;c++) // count columns
- printf("%d ",n-r); // print pattern
- printf("\n"); // new row
- }
- /*
- 1
- 1 2
- 1 2 3
- 1 2 3 4
- 1 2 3 4 5
- */
- printf("\n 1.3 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(c=0;c<=r;c++) // count columns
- printf("%d ",c+1); // print pattern
- printf("\n"); // new row
- }
- /*
- 1
- 2 1
- 3 2 1
- 4 3 2 1
- 5 4 3 2 1
- */
- printf("\n 1.4 \n\n");
- for(r=0;r<n;r++){ // for n rows
- d = r+1; // first digit in row
- for(c=0;c<=r;c++) // count columns
- printf("%d ", d--); // print pattern
- printf("\n"); // new row
- }
- /*
- 5
- 4 5
- 3 4 5
- 2 3 4 5
- 1 2 3 4 5
- */
- printf("\n 1.5 \n\n");
- for(r=0;r<n;r++){ // for n rows
- d = n-r; // first digit in row
- for(c=0;c<=r;c++) // count columns
- printf("%d ", d++); // print pattern
- printf("\n"); // new row
- }
- /*
- 1
- 2 3
- 4 5 6
- 7 8 9 10
- 11 12 13 14 15
- */
- printf("\n 1.6 \n\n");
- d = 1; // first digit
- for(r=0;r<n;r++){ // for n rows
- for(c=0;c<=r;c++) // count columns
- printf("%d ", d++); // print pattern
- printf("\n"); // new row
- }
- /*
- 1
- 1 1
- 1 1 1
- 1 1 1 1
- 1 1 1 1 1
- */
- printf("\n 2.0 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(b=n-r-1;b>0;b--) // count blanko
- printf(" "); // print blanko
- for(c=0;c<=r;c++) // count columns
- printf("1 "); // print pattern
- printf("\n"); // new row
- }
- /*
- 1
- 1 2
- 1 2 3
- 1 2 3 4
- 1 2 3 4 5
- */
- printf("\n 2.1 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(b=n-r-1;b>0;b--) // count blanko
- printf(" "); // print blanko
- d = 1; // first digit in row
- for(c=0;c<=r;c++) // count columns
- printf("%d ",d++); // print pattern
- printf("\n"); // new row
- }
- /*
- 5
- 5 4
- 5 4 3
- 5 4 3 2
- 5 4 3 2 1
- */
- printf("\n 2.2 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(b=n-r-1;b>0;b--) // count blanko
- printf(" "); // print blanko
- d = n; // first digit in row
- for(c=0;c<=r;c++) // count columns
- printf("%d ",d--); // print pattern
- printf("\n"); // new row
- }
- /*
- 1 1 1 1 1
- 1 1 1 1
- 1 1 1
- 1 1
- 1
- */
- printf("\n 3.0 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(b=0;b<r;b++) // count blanko
- printf(" "); // print blanko
- for(c=0;c<n-r;c++) // count columns
- printf("1 "); // print pattern
- printf("\n"); // new row
- }
- /*
- 1 2 3 4 5
- 1 2 3 4
- 1 2 3
- 1 2
- 1
- */
- printf("\n 3.1 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(b=0;b<r;b++) // count blanko
- printf(" "); // print blanko
- d = 1; // first digit in row
- for(c=0;c<n-r;c++) // count columns
- printf("%d ",d++); // print pattern
- printf("\n"); // new row
- }
- /*
- 5 4 3 2 1
- 5 4 3 2
- 5 4 3
- 5 4
- 5
- */
- printf("\n 3.2 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(b=0;b<r;b++) // count blanko
- printf(" "); // print blanko
- d = n; // first digit in row
- for(c=0;c<n-r;c++) // count columns
- printf("%d ",d--); // print pattern
- printf("\n"); // new row
- }
- /*
- 1 1 1 1 1
- 1 1 1 1
- 1 1 1
- 1 1
- 1
- */
- printf("\n 4.0 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(c=n-r;c>0;c--) // count columns
- printf("1 "); // print pattern
- printf("\n"); // new row
- }
- /*
- 1 2 3 4 5
- 2 3 4 5
- 3 4 5
- 4 5
- 5
- */
- printf("\n 4.1 \n\n");
- for(r=0;r<n;r++){ // for n rows
- d = r + 1; // first digit in row
- for(c=n-r;c>0;c--) // count columns
- printf("%d ",d++); // print pattern
- printf("\n"); // new row
- }
- /*
- 5 4 3 2 1
- 4 3 2 1
- 3 2 1
- 2 1
- 1
- */
- printf("\n 4.2 \n\n");
- for(r=0;r<n;r++){ // for n rows
- d = n - r; // first digit in row
- for(c=n-r;c>0;c--) // count columns
- printf("%d ",d--); // print pattern
- printf("\n"); // new row
- }
- /*
- 1
- 1 1
- 1 1 1
- 1 1 1 1
- 1 1 1 1 1
- */
- printf("\n 5.0 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(b=n-r-1;b>0;b--) // count blanko
- printf(" "); // print blanko
- for(c=0;c<=r;c++) // count columns
- printf("1 "); // print pattern
- printf("\n"); // new row
- }
- /*
- 1
- 1 2
- 1 2 3
- 1 2 3 4
- 1 2 3 4 5
- */
- printf("\n 5.1 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(b=n-r-1;b>0;b--) // count blanko
- printf(" "); // print blanko
- d = 1; // first digit in row
- for(c=0;c<=r;c++) // count columns
- printf("%d ",d++); // print pattern
- printf("\n"); // new row
- }
- /*
- 5
- 5 4
- 5 4 3
- 5 4 3 2
- 5 4 3 2 1
- */
- printf("\n 5.2 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(b=n-r-1;b>0;b--) // count blanko
- printf(" "); // print blanko
- d = n; // first digit in row
- for(c=0;c<=r;c++) // count columns
- printf("%d ",d--); // print pattern
- printf("\n"); // new row
- }
- /*
- 1 1 1 1 1
- 1 1 1 1
- 1 1 1
- 1 1
- 1
- */
- printf("\n 6.0 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(b=0;b<r;b++) // count blanko
- printf(" "); // print blanko
- for(c=0;c<n-r;c++) // count columns
- printf("1 "); // print pattern
- printf("\n"); // new row
- }
- /*
- 1 2 3 4 5
- 1 2 3 4
- 1 2 3
- 1 2
- 1
- */
- printf("\n 6.1 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(b=0;b<r;b++) // count blanko
- printf(" "); // print blanko
- d = 1; // first digit in row
- for(c=0;c<n-r;c++) // count columns
- printf("%d ",d++); // print pattern
- printf("\n"); // new row
- }
- /*
- 5 4 3 2 1
- 5 4 3 2
- 5 4 3
- 5 5
- 5
- */
- printf("\n 6.2 \n\n");
- for(r=0;r<n;r++){ // for n rows
- for(b=0;b<r;b++) // count blanko
- printf(" "); // print blanko
- d = n; // first digit in row
- for(c=0;c<n-r;c++) // count columns
- printf("%d ",d--); // print pattern
- printf("\n"); // new row
- }
- printf("\n\n");
- return 0;
- } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement