Saturday, 17 January 2015

C Program to print a diamond with stars pattern


This is a  C Program which prints out the diamond with stars pattern.

Diamond with stars (pattern)

PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i, j, k,n;
    printf("Enter number of lines[height of diamond] : \t");
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        for(j=i; j<n; j++)
        {
            printf(" ");
        }
        for(k=1; k<(i*2); k++)
        {
            printf("*");
        }
        printf("\n");
    }
    for(i=n-1; i>=1; i--)
    {
        for(j=n; j>i; j--)
        {
            printf(" ");
        }
        for(k=1; k<(i*2); k++)
        {
            printf("*");
        }
        printf("\n");
    }

    return 0;
}

OUTPUT : 
C Program to print diamond.

No comments:

Post a Comment