Write a C Program to Print Diamond Pattern
Program:
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, k, space=10;
for (i=0;i<=5;i++)
{
for (k=0;k<space;k++)
{
printf(" ");
}
for (j=0;j<2*i-1;j++)
{
printf("*");
}
space--;
printf("\n");
}
getch();
}
Output:
Enter number of rows
10
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
*****************
***************
*************
***********
*********
*******
*****
***
*
--------------------------------
Process exited after 4.725 seconds with return value 0
Press any key to continue . . .
Program:
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, k, space=10;
for (i=0;i<=5;i++)
{
for (k=0;k<space;k++)
{
printf(" ");
}
for (j=0;j<2*i-1;j++)
{
printf("*");
}
space--;
printf("\n");
}
getch();
}
Output:
Enter number of rows
10
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
*****************
***************
*************
***********
*********
*******
*****
***
*
--------------------------------
Process exited after 4.725 seconds with return value 0
Press any key to continue . . .
0 Comments:
Post a Comment