我试图打印一个空心矩形。但它不会正确打印出来。这就是我到目前为止所拥有的。它打印但不是空心矩形。它生成 50 到 1 之间的随机整数。
void randomRectangle(){
srand(time(NULL));
int counter = 0;
int counter2 = 0;
int height = rand() % 50;
int width = rand() % 50;
printf("Now printng a rectangle.\n");
printf("Height = %d\n" "Width = %d\n", height, width);
while(counter < height){
counter++;
counter2 = 0;
while(counter2 < width){
if (((counter2 > 1)&&(counter2 < height))&&((counter > 1)&&(counter < height))){
printf(" ");
}
else if((counter2 != 0)&&(counter != 0)){
printf("* ");
}
counter2++;
}
printf("\n");
}