我似乎无法循环这段代码。它是一个简单的代码,用于显示输入的最小数字、最大数字以及用户输入的数字数量。如果用户输入 0,它也应该退出。它是葡萄牙语的,所以请查看命令侧面的说明。它似乎工作正常,但它只执行一次,我不知道如何让它循环。 代码:
#include <stdio.h>
int main()
{
int x,
y,
soma,
maior;
printf("Digite o proximo numero ou digite 0 para sair\n ");\\\Type the next number or type 0 to exit.
scanf("%d", &x);
y=x;
maior=x; \\\maior = the biggest number. soma = amount of numbers and y the smallest number.
soma=1;
if(x==0)
return(0);
else
printf("Digite o proximo numero\n");\\\type the next number.
scanf("%d", &x);
if (x>maior)\\\If X is bigger then the biggest number so far.
{
maior=x;
soma=soma+1;
printf("O maior numero eh: %d\n",maior);\\\prints current biggest number
printf("O menor numero eh: %d\n", y);\\\prints smaller number
printf("A quantidade de numeros digitados foi %d", soma);\\\How many numbers were typed in
}
else
if (x==0)
{
return(0);
}
else
if (x<y)\\If x is smaller then the smallest number so far.
{
y=x;
soma=soma+1;
printf("O maior numero eh: %d\n",maior);
printf("O menor numero eh: %d", y);
printf("A quantidade de numeros digitados foi %d", soma);
}
}
最佳答案
我在代码中没有看到循环语句,您需要用 while(true) 或 for(;;) block 包围要循环的部分。通常,当到达主函数末尾时,程序就会终止。
关于c - 我不知道如何循环这段代码。每次我使用 while 它只是重复第一个 printf 句子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28661611/