Advertisement
Procy0n

Unit 1, Diamond

Jul 22nd, 2011
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4.     int height;
  5.  
  6.     printf("Please enter the height of the first half of the diamond:\n");
  7.     scanf("%d", &height);
  8.  
  9.     if (height < 1) {
  10.     printf("Invalid user input. Minimum size of the diamond is one.\n");
  11.     return 0;
  12.     }
  13.  
  14.     for (int y = 0; y <= height * 2; y++) {
  15.         for (int x = 0; x <= height * 2; x++) {
  16.         if (x + y == height || x - y == height ||
  17.             y - x == height || x + y == 3 * height)
  18.             printf("*");
  19.         else
  20.         printf(" ");
  21.     }
  22.     printf("\n");
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement