这哪里有错啊,该改哪里呢

img


改了很多次括号位置都没有改对,但是又看不出来有什么问题,有没有人能帮我解答一下,刚刚入门还有点混乱

输出放在循环外(return语句前面)

这么写,供参考:

#include <stdio.h>
#include <math.h>
int main()
{
    int a, n, sa, max = -1;
    scanf("%d", &n);
    while (n--){
        scanf("%d", &a);
        sa = (int)sqrt(a);
        if (a == sa * sa)
            continue;
        if (max == -1 || max < a)
            max = a;
    }
    printf("%d", max);
    return 0;
}

【以下回答由 GPT 生成】

代码中有一处错误,"sum"应该是累加器而不是减法操作。另外,头文件应该是<stdio.h>而不是<iostream>, 并且可以使用数组来存储输入的整数而不是int类型。

以下是修改后的代码:

#include <stdio.h>
#include <math.h>

int main() {
    int n, max = -1;
    long long int a[100000];
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
    }

    for (int i = 0; i < n; i++) {
        long long int num = a[i];
        int isPerfectSquare = 0;
        for (long long int j = 1; j * j <= num; j++) {
            if (j * j == num) {
                isPerfectSquare = 1;
                break;
            }
        }
        if (!isPerfectSquare && num > max) {
            max = num;
        }
    }

    printf("%lld\n", max);
    return 0;
}

希望以上信息对您有所帮助。如果您有任何疑问,请随时提问。



【相关推荐】



如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^