c编程输出如下图形。 ** ** * * * * * ***
时间: 2023-11-15 08:03:59 浏览: 92
这个图形可以使用以下两种方法来输出:
1.方法一:使用多个printf语句输出
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("** **\n");
printf("* *\n");
printf("* * \n");
printf("* \n");
printf("***\n");
system("pause");
return 0;
}
2.方法二:使用while嵌套循环输出
#include <stdio.h>
#include <Windows.h>
#include <stdlib.h>
int main() {
int a ,b; //定义两个变量-a用来控制内循环;b用来控制外循环
char x = '*';
a = 1;
while (a <= 5) //外循环-大环境-while控制行数
{
b = 1;
while (b <= 5) //内循环(五脏六腑)-while控制输出*的个数-每五个为一行
{
if ((a == 1 && (b == 1 || b == 2 || b == 6 || b == 7)) || (a == 2 && (b == 1 || b == 6 || b == 7)) || (a == 3 && (b == 1 || b == 5 || b == 6 || b == 7)) || (a == 4 && (b == 1 || b == 5 || b == 7)) || (a == 5 && (b == 1 || b == 2 || b == 3 || b == 4 || b == 5 || b == 7)))
{
printf("%c", x);
}
else
{
printf(" ");
}
b++;
}
printf("\n");
a++;
}
return 0;
}
阅读全文