Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- diamond star wall pattern with abs() and longest row v1.c
- Enter the number of stars in the longest row of diamond, ns.
- The number of stars in the longest row of diamond is same as
- the number of rows of the upper triangle of diamond.
- Diamond will have 2*ns-1 raws.
- We enter maximum number of stars in single row,
- then we draw such a diamond.
- ns = 5
- ----*-
- ---*-*-
- --*-*-*-
- -*-*-*-*-
- *-*-*-*-*-
- -*-*-*-*-
- --*-*-*-
- ---*-*-
- ----*-
- row spaces,j * i
- 0. 4 1 -4
- 1. 3 2 -3
- 2. 2 3 -2
- 3. 1 4 -1
- 4. 0 5 0
- 5. 1 4 1
- 6. 2 3 2
- 7. 3 2 3
- 8. 4 1 4
- */
- #include "stdio.h"
- int main(void)
- {
- /*
- i counter in loop for rows
- j counter in print loops
- ns number of rows of the upper triangle of diamond
- or number of stars in the longest row of diamond
- */
- int i, j, ns;
- printf("\n the number of stars in the longest row of diamond, ns = ");
- scanf("%d", &ns); // try 5, 6 or 30
- printf("\n");
- for (i = -ns + 1; i < ns; i++) // loop for rows
- {
- // printf("%*s", abs(i), ""); // this line or for (j = 0; j < abs(i); j++)
- for (j = 0; j < abs(i); j++) // print "-"
- printf("-");
- for (j = 0; j < ns - abs(i); j++) // print "*-"
- printf("*-");
- printf("\n"); // new row
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement