编程图形4.9

//program 4.9 output a box with given width and height

include

int main(){
const unsigned int MIN_SIZE = 3;
unsigned int width = 0;
unsigned int height = 0;
//read in required width and height
printf("enter values for the width and height (minimum of %u):", MIN_SIZE);
scanf_s("%u%u", &width, &height);

//walidate width and height values
if (width < MIN_SIZE){
    printf("\nwidth value of %u is too small.setting it to %u.", width, MIN_SIZE);
}
if (height < MIN_SIZE){
    printf("\nheight value of %u is too small.", height, MIN_SIZE);
}
//output the top of the box with width asterisks
for (unsigned int i = 0; i < width; ++i)
    printf("*");
//output height_2 rows of width charcaters with * at each end and spaces inside
for (unsigned int j = 0; j < height - 2; ++j){
    printf("\n*");
    //next draw the spaces
    for (unsigned int i = 0; i < width - 2; ++i)
        printf(" ");
    printf("*");
}
//output the bottom of the box 
printf("\n");
for (unsigned int i = 0; i < width; ++i)
    printf("*");
printf("\n");
return 0;

}

你可能感兴趣的:(编程图形4.9)