During this period of time, I was busy studying, and I didn’t update the technical articles on the website. Today I will post one~
The project uses do while , if , for etc;
Project example:
#include <stdio.h>
int main(int scanfs) {
int a;
int hs;
int ds,dd;
do {
scanf("%d", &a); // 输入自定义行数三角形
scanf("%d",&scanfs); // 输入判断自行正三角形或倒三角形
if (scanfs == 1) { // 判断成功后, 开始执行正三角形
for (int b = 1; b <= a; b++) {
for (int c = 2 * 10; c >= b; c--)
printf(" ");
for (int c = 1; c <= 2 * b - 1; c++)
printf("*");
printf("\n");
}
}
/// 倒三角形
if (scanfs == 2) {
scanf("%d", &hs); // 判断是倒三角形后, 需要重新输入行数
for (ds = 0; ds < hs; ds++) {
for (dd = 0; dd < ds; dd++)
printf(" ");
for (dd = hs - dd; dd > 0; dd--)
printf("* ");
printf("\n");
}
}
}
while (scanfs != 1 && scanfs != 2); // 判断不是 1或2 ,重新执行 do 里的语句
return 0;
}
No need to enter the number of inverted triangle rows twice:
#include <stdio.h>
int main(int scanfs) {
int a;
int hs;
int ds,dd;
do {
scanf("%d", &a); // 输入自定义行数三角形
scanf("%d",&scanfs); // 输入判断自行正三角形或倒三角形
if (scanfs == 1) { // 判断成功后, 开始执行正三角形
for (int b = 1; b <= a; b++) {
for (int c = 2 * 10; c >= b; c--)
printf(" ");
for (int c = 1; c <= 2 * b - 1; c++)
printf("*");
printf("\n");
}
}
/// 倒三角形
if (scanfs == 2) {
// scanf("%d", &hs); // 判断是倒三角形后, 需要重新输入行数
for (ds = 0; ds < a; ds++) {
for (dd = 0; dd < ds; dd++)
printf(" ");
for (dd = a - dd; dd > 0; dd--)
printf("* ");
printf("\n");
}
}
}
while (scanfs != 1 && scanfs != 2); // 判断不是 1或2 ,重新执行 do 里的语句
return 0;
}
Execution effect: