Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- pattern with numbers v1.c
- Enter a number between 1 and 9 , n = 9
- 1 - - - - - - - - - - - - - - - - 1
- 1 2 - - - - - - - - - - - - - - 2 1
- 1 2 3 - - - - - - - - - - - - 3 2 1
- 1 2 3 4 - - - - - - - - - - 4 3 2 1
- 1 2 3 4 5 - - - - - - - - 5 4 3 2 1
- 1 2 3 4 5 6 - - - - - - 6 5 4 3 2 1
- 1 2 3 4 5 6 7 - - - - 7 6 5 4 3 2 1
- 1 2 3 4 5 6 7 8 - - 8 7 6 5 4 3 2 1
- 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1
- 1 2 3 4 5 6 7 8 - - 8 7 6 5 4 3 2 1
- 1 2 3 4 5 6 7 - - - - 7 6 5 4 3 2 1
- 1 2 3 4 5 6 - - - - - - 6 5 4 3 2 1
- 1 2 3 4 5 - - - - - - - - 5 4 3 2 1
- 1 2 3 4 - - - - - - - - - - 4 3 2 1
- 1 2 3 - - - - - - - - - - - - 3 2 1
- 1 2 - - - - - - - - - - - - - - 2 1
- 1 - - - - - - - - - - - - - - - - 1
- getch(); is here for you to see how this algorithm works.
- After that, delete lines with getch();
- and printf("- "); replace with printf(" ");
- */
- #include "stdio.h"
- int main(void)
- {
- int i, j, n, s;
- printf("\n Enter a number between 1 and 9 , n = ");
- scanf("%d", &n);
- printf("\n\n");
- for (i = 1; i <= n; i++) // printing upper half of the pattern, row by row
- {
- for (j = 1; j <= i; j++) // printing left numbers in row i
- {
- printf("%d ",j);
- }
- getch();
- for(s=1; s <= 2 * (n - i); s++) // printing spaces in row i
- {
- printf("- "); // change with: printf(" ");
- }
- getch();
- for (j = i; j >= 1; j--) // printing right numbers in row i
- {
- printf("%d ",j);
- }
- printf("\n"); // go to next row i
- }
- for (i = n-1; i >= 1; i--) // printing lower half of the pattern, row by row
- {
- for (j = 1; j <= i; j++) // printing numbers
- {
- printf("%d ",j);
- }
- getch();
- for(s=1; s <= 2 * (n - i); s++) // printing spaces
- {
- printf("- "); // change with: printf(" ");
- }
- getch();
- for (j = i; j >= 1; j--) // printing numbers
- {
- printf("%d ",j);
- }
- printf("\n"); // go to next row i
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement