So I've looked up and only found normal triangles questions out there.
This one is a bit tricky.
Given a N, your program should create an asterisk unfilled triangle with a N side size.
Example 1
Inform N: 1
*
Example 2:
Inform N: 2
**
*
Example 3:
Inform N: 3
***
**
*
Example 4:
Inform N: 4
****
* *
**
*
Example 5:
Inform N: 5
*****
* *
* *
**
*
Here's my attempt, I could only make a filled triangle inefficiently
void q39(){
int n,i,b;
printf("Inform N: ");
scanf ("%i",&n);
for ( i = 0; i < n; ++i)
{
printf("*");
for ( b = 1; b < n; ++b)
{
if (i==0)
{
printf("*");
}
else if (i==1 && b>1)
{
printf("*");
}
else if (i==2 && b>2)
{
printf("*");
}
else if(i==3 && b>3){
printf("*");
}
else if(i==4 && b>4){
printf("*");
}
else if(i==5 && b>5){
printf("*");
}
else if(i==6 && b>6){
printf("*");
}
else if(i==7 && b>7){
printf("*");
}
else if (i==8 && b>8){
printf("*");
}
}
printf("
");
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…