Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- number_pattern_v1.c
- 12345
- 2345
- 345
- 45
- 5
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include <stdio.h>
- void print_pattern_v1(int rows)
- {
- int r,c,first_number=1; // r and c is for row and column
- for(r=0;r<rows;r++)
- {
- for(c=0;c<rows-r;c++)
- printf("%d",first_number+c);
- first_number++;
- printf("\n");
- }
- }
- void print_pattern_v2(int rows)
- {
- int r,c; // r and c is for row and column
- for(r=0;r<rows;r++)
- {
- for(c=0;c<rows-r;c++)
- printf("%d",r+1+c);
- printf("\n");
- }
- }
- void print_pattern_v3(int rows)
- {
- int r,c; // r and c is for row and column
- for(r=0;r<rows;r++)
- {
- for(c=0;c<rows;c++)
- if(c+1>r)
- printf("%d",c+1);
- printf("\n");
- }
- }
- void print_pattern_v4(int rows)
- {
- int arr[]={1,2,3,4,5,6,7,8,9};
- int r,c; // r and c is for row and column
- if( rows<1 || rows>9 )
- {
- printf("\n Rows must be between 1 and 9 \n");
- return;
- }
- for(r=0;r<rows;r++)
- {
- for(c=0;c<rows;c++)
- if(c+1>r)
- printf("%d",arr[c]);
- printf("\n");
- }
- }
- int main(void)
- {
- printf("\n Version 1: \n\n");
- print_pattern_v1(5);
- printf("\n Version 2: \n\n");
- print_pattern_v2(5);
- printf("\n Version 3: \n\n");
- print_pattern_v3(5);
- printf("\n Version 4: \n\n");
- print_pattern_v4(5);
- return 0;
- } // main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement