Hey, newbie programmer here. I've been trying to program something and I'm having a little trouble.
I needed to ask for user input for the amount of rows in the triangle. The number of rows can only be odd numbers and less than 10.
The output should look like
*
**
***
**
*
For a 5 row triangle. I got the input thing down I think but I can't find out how to put the * in that pattern. I'm trying to use a nested for loop, I'm I going at it with the wrong loop? The spaces need to be there too.
Here is my code, it's not done, I couldn't get it to work for 3 so I stopped.
printf("How many rows do you want?\n");
scanf("%i", &c);
switch(c){
case 0:
printf("You can't have 0 rows\n");
break;
case 1:
printf("*")
break;
case 2:
printf("Your number must be an odd number\n");
break;
case 3:
for(counter=1; counter<=c; counter++){
for(a=1; a<=counter; a++){
printf("*");}
printf("\n\n");
break;
I'm sure I am just stupid but I can't figure how to make the triangle decrease in *.
2007-02-19
09:53:07
·
4 answers
·
asked by
Gearz
2
in
Computers & Internet
➔ Programming & Design