February 4, 2011

C Program To print pyramid output


To Print Output like
*
**
***
****
*****
******



#include<stdio.h>
#include<conio.h>

void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
printf("\n");
for(j=1;j<=i;j++)
printf("*");
}
getch();
}



TO  reverse the output
*****
****
***
**
*


#include<stdio.h>
#include<conio.h>

void main()
{
int i,j;
clrscr();
for(i=5;i>=5;i--)
{
printf("\n");
for(j=1;j<=i;j++)
printf("*");
}
getch();
}



We can play with the code to get some more output
1
12
123
1234
12345


#include<stdio.h>
#include<conio.h>

void main()
{
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
printf("\n");
for(j=1;j<=i;j++)
printf("%d",j);
}
getch();
}



To reverse the output
12345
1234
123
12
1


#include<stdio.h>
#include<conio.h>

void main()
{
int i,j;
clrscr();
for(i=5;i>=1;i--)
{
printf("\n");
for(j=1;j<=i;j++)
printf("%d",j);
}
getch();
}

Hope you liked my posts, give comments if you have any doubts.. :)

Related Posts :



0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Related Posts with Thumbnails