Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include <stdlib.h>
- int main(void)
- {
- int size=0;
- while (size%2==0)
- {
- size = get_int("What odd size diamond? ");
- }
- int spaces=0;
- //draw top half of diamond
- for (int i=1; i<=size; i=i+2)
- {
- //print spaces first
- spaces = (size-i)/2;
- for (int j=0; j<spaces; j++)
- {
- printf(" ");
- }
- //print the hashes next
- for (int j=0; j<i; j++)
- {
- printf("#");
- }
- printf("\n");
- }
- //draw bottom half
- for (int i=size-2; i>=1; i=i-2)
- {
- //print spaces first
- spaces = (size-i)/2;
- for (int j=0; j<spaces; j++)
- {
- printf(" ");
- }
- //print the hashes next
- for (int j=0; j<i; j++)
- {
- printf("#");
- }
- printf("\n");
- }
- }
Add Comment
Please, Sign In to add comment