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

Wednesday, November 5, 2014

Program to print diamond pattern 4 in C.

Diamond Pattern 4

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

/* Program to print diamond pattern 4 */
#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("%d",i);

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

printf("\n");
}


for (i = n; i >=1; 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");
}
printf("\n");
printf("\n----------------------------------\n");
getch();
}

No comments: