我正在处理的程序输出该符号的直角三角形,其边数等于该数字。它应该做的是终止,如果你输入0,否则它应该再次要求一个新的输入。该符号的直角三角形,边数等于该数字
所以我的问题是如何让它终止,如果你输入0,否则要求另一个输入?我知道我可能需要使用while循环。但是,我该如何改变它?
这里是我的代码:
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
char s; /*s is symbol (the input)*/
int a, b, n; /*n is number of rows (the input)*/
printf("Please type the symbol of the triangle:...\n"); /*Ask for symbol input*/
scanf_s("%c", &s, 1);
printf("Please type a positive non-zero number between 5 and 35:...\n"); /*Ask for number of rows input*/
scanf_s("%d", &n);
assert(n >= 5 && n <= 35);
for (a = 1; a <= n; a++) /*How many rows to display+create*/
{
for (b = 1; b <= a; b++)
{
printf("%c", s);
}
printf("\n");
}
system("PAUSE");
}
所以我的问题是,“如何在你输入0结束,否则它会再次询问新的输入。” 我知道我可能需要while循环使用。但是,我如何改变它? –
不要在评论中提问。相反,请将其包含在您的实际问题中。 – Laurel