gpt4 book ai didi

c - 嗨,有人可以帮我解决这个循环吗

转载 作者:行者123 更新时间:2023-11-30 21:43:02 24 4
gpt4 key购买 nike

很抱歉问这个问题,但我没有其他地方可去,而且我无法找到解决方案。我很擅长编程语言 Pascal,所以这种 C 语言对我来说似乎很熟悉,但是添加一个 if 函数来改变 while 循环的整个结构对我来说太复杂了。请提供任何帮助,我们将不胜感激。

The array variable consists of a sequence of ten numbers. Inside the while loop, you must write two if conditions, which change the flow of the loop in the following manner (without changing the printf command):

  • If the current number which is about to be printed is less than 5, don't print it.
  • If the current number which is about to be printed is greater than 10, don't print it and stop the loop.

    Notice that if you do not advance the iterator variable i and use the continue derivative, you will get stuck in an infinite loop.
#include <stdio.h>

int main()
{
int array[] = {1, 7, 4, 5, 9, 3, 5, 11, 6, 3, 4};
int i = 0;

while (i < 10)
{
/* your code goes here */

printf("%d\n", array[i]);
i++;
}
return 0;
}

最佳答案

它正在测试您对 C 流控制的理解。您正在寻找的是这样的:

if (array[i] < 5) {i++; continue; }  // increment, go back to while
if (array[i] > 10) break; // leave while

关于c - 嗨,有人可以帮我解决这个循环吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17224987/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com