Displaying a pyramid of stars
This example shows how to display a pyramid of stars.
/*to display a pyramid of stars
*
* *
* * *
* * * *
*/
/*
**********************
www.botskool.com
**********************
*/
#include<stdio.h>
#include<conio.h>
void main()
{ int i,j,k,n=5;
clrscr();
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
printf(" ");
for(k=1;k<=2*i-1;k++)
if(k%2!=0)
printf("*");
else
printf(" ");
printf("\n");
}
getch();
}
/*
**********************
www.botskool.com
**********************
*/
Output of the above example will be like shown below:-

Terms of Agreement:
By using this code, you agree to the following terms-
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
2) You MAY NOT redistribute this code (for example to a web site) without written permission from us. Failure to do so is a violation of copyright laws.
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which may have placed in the code or code's description.
Tags:


Recent comments
2 days 10 hours ago
6 days 13 hours ago
2 weeks 1 day ago
2 weeks 1 day ago
2 weeks 4 days ago