Credits

Tuesday, February 17, 2009

Brain Twister

*
**
***
****
*****

The program below displays the triangle of asterisks above.



[+/-] show/hide



#include stdio.h /*enclose stdio.h with <> */
main()
{
int x,y;
for(x=1;x<=5;x++)
{ for (y=1;y<=x;y++)
printf("*");
printf("\n");
}
getche();
}

The outer loop above controls the line by line of asterisks while the inner loop controls the number of asterisks per line.

Using the program above as guide, make the needed C program to display the following outputs:
*****
****
***
**
*

*
**
***
****
*****

*
* *
* * *
* * * *
* * * * *

AddThis