c语言中程序的循环控制 大小值的判断及赋值。
输出长度大于高度的矩形。
1、
#include <stdio.h>
int main(void)
{
int i, j, height, width, min, max;
printf("please input the height and width.\n");
printf("height = "); scanf("%d", &height);
printf("width = "); scanf("%d", &width);
min = height > width ? height;
max = height > width ? height:width;
for(i = 1; i <= min; i++)
{
for(j = 1; j <= max; j++)
{
putchar('*');
}
putchar('\n');
}
return 0;
}
2、
#include <stdio.h>
int main(void)
{
int i, j, height, width, tmp;
puts("please input the height and width");
printf("height = "); scanf("%d", &height);
printf("width = "); scanf("%d", &width);
if (height > width)
{
tmp = width;
width = height;
height = tmp;
}
for(i = 1; i <= height; i++)
{
for(j = 1; j <= width; j++)
{
putchar('*');
}
putchar('\n');
}
return 0;
}