简体   繁体   English

某处有错误,我找不到。 代码有效,但结果错误。 我想修复,但我不知道它在哪里。 请帮助我

[英]there is mistake somewhere,i can't find it. code is work but it s wrong result. i want to fix but i don't know where is it. pls help me

there is mistake somewhere,i can't find it. 某处有错误,我找不到。 code is work but it s wrong result. 代码有效,但结果错误。 i want to fix but i don't know where is it. 我想修复,但我不知道它在哪里。 pls help me 请帮助我

#include <stdio.h>
int main() {
    int elemansayisi;   //size
    printf("Eleman sayisini giriniz : ");
    scanf("%d", &elemansayisi); //size
    printf("\n");
    int dizi[elemansayisi], i, j; //array
    int enBuyuk = dizi[0]; //first biggest element 
    for (i = 0; i < elemansayisi; i++) {
        printf("Dizinin  elemanlanrini giriniz : "); //getting array from user
        scanf("%d", &dizi[i]);
    }
    printf("\n");
    for (i = 0; i < elemansayisi; i++) {

        printf("dizinin %d. elemani: %d\n", i, dizi[i]);  //print array 
        printf("\n");

    }

    for (j = 0; j <= elemansayisi; j++) {

        if (enBuyuk <= dizi[j])  //find biggest element in array

            enBuyuk = dizi[j];

    }

    printf("En buyuk deger : %d", enBuyuk);
    return 0;
}

This sets enBuyuk to a value that is undefined! enBuyuk设置为未定义的值!

int enBuyuk = dizi[0]; //first biggest element 

Instead, move this line to just above your for-loop. 而是将这条线移到for循环的正上方。


for (j = 0; j <= elemansayisi; j++) {  

This should be strictly less than (remove the = sign) 此值应严格小于(删除=号)

int enBuyuk = dizi[0]; // Move line here
for (j = 0; j < elemansayisi; j++) {

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 pset5 Speller - 我不知道代码有什么问题。 谁能指导我找出我的错误? 我已经包含了所有内容 - pset5 Speller - I don't know what's wrong with the code. Could anyone guide me to find my mistake? I've included everything 这是 Cs50 问题 set1 现金。 我不知道这段代码有什么问题有人可以帮助我 - This is Cs50 problem set1 cash. I don't know what's wrong with this code can someone help me 家庭作业:我在某个地方有内存泄漏,但我找不到它。 关于如何更有效地使用valgrind的任何提示? - Homework: I have a memory leak somewhere, but I can't find it. Any tips on how to use valgrind more effectively? 如何使用 C 找到子数组中所有元素之和为 0 的最大子数组的长度我不知道错误在哪里.. 请任何人告诉我 - how do I find length of largest subarray with sum of all elements in subarray is 0 using C i don't know where the mistake is.. please anyone tell me 不知道这段代码有什么问题? - I don't know what's going wrong with this code? 我不知道为什么会出现这个错误 - i don't know why it appears this mistake 一个简单的C switch语句程序错误。 我无法构建和运行它。 我不知道为什么 - A simple C switch statement program error. I cant build and run it. I don't know why 我在“返回”中看到了一些我不明白的代码。 有人可以帮助我吗? - I saw some code in "return" that i don't understand. Can somebody help me? 无法运行我的代码,我不知道为什么它不起作用 - Can't run my code, and I don't know why it doesn't work 我真的不知道怎么了 - I really don't know what's wrong
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM