Hello
I'd like to program any number so that the pyramid is tilted 90 degrees to the right in *
, but for example, if it's 3, it's output as follows, and if you type 0, it stops.
*
**
***
**
*
I programmed it as follows, but it doesn't work as shown in the attachment.
Where is the mistake?
#include<stdio.h>
int main() {
inti,j,len,k;
for(;;){
scanf("%d", &len);
if(len==0){break;}
for(i=1;i<=len;i++){
for (j=1; j<=i;j++)
printf("*");
printf("\n");
}
for(k=len-1;k>0;k--){
for (j=1; j<=len-1;j++)
printf("*");
printf("\n");
}
}
}
The loop condition in the comment section below is incorrect. Because j<len-1
, you always write *
as many as input values -1
.I think it's a snake's foot, but the correct answer is j<=k
.
#include<stdio.h>
int main() {
inti,j,len,k;
for(;;){
scanf("%d", &len);
if(len==0){break;}
for(i=1;i<=len;i++){
for (j=1; j<=i;j++)
printf("*");
printf("\n");
}
for(k=len-1;k>0;k--){
for(j=1;j<=len-1;j++)/*<= Loop condition is j<len-1*/
printf("*");
printf("\n");
}
}
}
529 Uncaught (inpromise) Error on Electron: An object could not be cloned
547 Who developed the "avformat-59.dll" that comes with FFmpeg?
546 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
700 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.