c - 我不知道如何循环这段代码。每次我使用 while 它只是重复第一个 printf 句子

标签 c

我似乎无法循环这段代码。它是一个简单的代码,用于显示输入的最小数字、最大数字以及用户输入的数字数量。如果用户输入 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/

相关文章:

c - 从 C 函数返回的字符串是垃圾

C -fscanf 导致中止陷阱 : 6 on EOF

将 chrome 原生客户端中的 pp::Var 数组转换为 C 整数数组

c++ - 多线程交换 2 个预定义指针到 1 个静态指针线程安全吗?

C 宏 : concatenate symbols conditionally

c - 如果函数声明不在头文件中,是否需要 static 关键字?

c - 全局指针(链表头)未正确更新

冲突类型中的 C 错误

c++ - 如何将 new 更改为 malloc?

c - 扫描 double 和字符