Brijmohan lal Sahu - Facebook
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Wednesday, November 5, 2014

Program to print diamond pattern 3 in C.

Diamond Pattern 3

Code Box
-------------------------------------

/* Program to print diamond pattern 3 */
#include <stdio.h>
#include <conio.h>
void main()
{

int i, j, k,n;
clrscr();

printf("Enter the number of stars: ");
scanf("%d",&n);

printf("\n---------------Diamond pattern-------------------\n");

for (i = 1; i <= n; i++)
{
for (j = 0; j < (n - i); j++)
printf(" ");
for (j = 1; j <= i; j++)
printf(" ");

for (k = 1; k <=i; k++)
printf("%d",i);

printf("\n");
}


for (i = n; i >= 1; i--)
{
for (j = 0; j < (n - i); j++)
printf(" ");

for (j = 1; j <= i; j++)
printf("%d",i);
for (k = 1; k < i; k++)
printf(" ");
printf("\n");
}
printf("\n");
printf("\n----------------------------------\n");
getch();
}

No comments: