+ 1

its not work. can anyone explain to me why this? ( find the highest value and the input position that I want to output )

int main() { int number[MAX], i, j, max=0, num_pos=0; printf("Input 5 integers: \n"); for(i = 0; i < MAX; i++) { scanf(" %d", &number[i]); } for(j = 0; j < MAX; j++) { if(number[j] > max) { max = number[j]; num_pos = j; } } printf("Highest value: %d\nPosition: %d\n", max, num_pos+1); return 0; }

20th Jul 2022, 3:58 PM
Piyumi Nadeesha Weerarathna
Piyumi Nadeesha Weerarathna - avatar
8 Respostas
+ 2
int number[ MAX ]; here MAX is undeclared yet.. Error. Declare MAX and initialize value before using it...
20th Jul 2022, 4:06 PM
Jayakrishna 🇼🇳
+ 1
int MAX;đŸ€” did you say this.
20th Jul 2022, 4:10 PM
Piyumi Nadeesha Weerarathna
Piyumi Nadeesha Weerarathna - avatar
+ 1
#include <stdio.h> int MAX=5; int main() { int number[MAX],i,j, max=0: /*This line generate the error*/ int num_pos=0; printf("Input 5 integers: \n"); for(i = 0; i < MAX; i++) { scanf(" %d", &number[i]); } for(j = 0; j < MAX; j++) { if(number[j] > max) { max = number[j]; num_pos = j; } } printf("Highest value: %d\nPosition: %d\n", max, num_pos+1); return 0; }
20th Jul 2022, 4:28 PM
Piyumi Nadeesha Weerarathna
Piyumi Nadeesha Weerarathna - avatar
+ 1
oh god. I didn't see it. thank you, sir
21st Jul 2022, 1:23 AM
Piyumi Nadeesha Weerarathna
Piyumi Nadeesha Weerarathna - avatar
0
Yes. also value. before the array declaration. int MAX = 5; //ex or #define MAX 5 Also include header #include <stdio.h>
20th Jul 2022, 4:12 PM
Jayakrishna 🇼🇳
0
But It doesn't work😒
20th Jul 2022, 4:20 PM
Piyumi Nadeesha Weerarathna
Piyumi Nadeesha Weerarathna - avatar
0
Update code? Better to Save in playground and share link.
20th Jul 2022, 4:22 PM
Jayakrishna 🇼🇳
0
You are using : (colon) instead of ; (semicolon) after max=0 :👈 => max = 0 ;
20th Jul 2022, 4:38 PM
Jayakrishna 🇼🇳