Print Diamond Shape - C Language Programming



Print Diamond Shape for number of row enter by user using * like -

    *
   ***
  *****
   ***
    *

Click here to open this program in Turbo C++

/*******************************************************
 Statement - Print Diamond
 Programmer - Vineet Choudhary
 Written For - http://developerinsider.co
 *******************************************************/

#include <stdio.h>
#include <conio.h>

void main()
{
    int n, c, k, space = 1;
    clrscr();
    
    printf("Enter number of rows\n");
    scanf("%d", &n);
    
    space = n - 1;
    
    for (k = 1; k <= n; k++)
    {
        for (c = 1; c <= space; c++)
            printf(" ");
        
        space--;
        
        for (c = 1; c <= 2*k-1; c++)
            printf("*");
        
        printf("\n");
    }
    
    space = 1;
    
    for (k = 1; k <= n - 1; k++)
    {
        for (c = 1; c <= space; c++)
            printf(" ");
        
        space++;
        
        for (c = 1 ; c <= 2*(n-k)-1; c++)
            printf("*");
        
        printf("\n");
    }
    
    getch();
}
Join

Search articles

Search titles, tags and article content.

    You've successfully subscribed to Developer Insider
    Your account is ready. Welcome to Developer Insider
    Welcome back! You've successfully signed in
    Success! Your account is fully activated, you now have access to all content.