gpt4 book ai didi

c - 在数组中使用 GOTO

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

我必须编写一个 C 程序(不使用递归、else、for、while、do {} while 并且使用 if 的构造不得包含“return”)来从数组中查找最大数字。所以现在这是我的代码:

#include <stdio.h>
void function()
{
int i, maximum;
int array[] = {1,2,3,4};
maximum = array[0];
if (array[i] > maximum)
{
maximum = array[i];
}
printf("The biggest element from the array is %d\n ", maximum);
}

int main(void)
{
functie();
}

但我不知道如何在不使用“for”的情况下读取数组。请帮我?我看到一些使用 GOTO 的内容,但我不知道如何...

最佳答案

您可以使用goto语句来创建循环。示例取自 here .

int i = 0;

firstLoop:
printf("%d",i);
i++;
if(i<10)
goto firstLoop;
printf("\nout of first loop");

但是,使用 goto 是一种不好的做法,因为它会破坏程序流程并使程序更难以阅读、理解和调试。

关于c - 在数组中使用 GOTO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33197066/

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