[英]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.