美文网首页
编程图形4.9

编程图形4.9

作者: Zdhj | 来源:发表于2017-03-23 12:09 被阅读17次

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

include<stdio.h>

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

      本文链接:https://www.haomeiwen.com/subject/kyuznttx.html