Hi everybody,
I stumbled upon this site while looking for some help to a problem I have and this seems to be a great community. My question has to do with a for loop and the printing of a triangle. What I need to do is print a triangle like this:
Triangle
Code:
*
***
*****
*******
*********
***********
However, I am getting something like this:
Triangle
Code:
*
**
***
****
*****
******
*******
********
*********
**********
***********
My code so far is:
Code:
#include <stdio.h>
main()
{
int width=0, row=0, column=0;
scanf("%d", &width);
for(row=1; row<=width; row++)
{
for(column=1; column<=row; column++)
printf("*");
printf("\n");
}
return 0;
}
So my question is how do I get the first asterisk to be in the middle of the triangle like this first example I gave. I would appreciate any help you can give me since I am very new to computer programming. Thanks!
Code tags added by Hammer