+ 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; }
8 Respostas
+ 2
int number[ MAX ]; here MAX is undeclared yet.. Error.
Declare MAX and initialize value before using it...
+ 1
int MAX;đ€ did you say this.
+ 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;
}
+ 1
oh god. I didn't see it. thank you, sir
0
Yes. also value. before the array declaration.
int MAX = 5; //ex or #define MAX 5
Also include header
#include <stdio.h>
0
But It doesn't workđ
0
Update code?
Better to Save in playground and share link.
0
You are using : (colon) instead of ; (semicolon) after max=0 :đ
=> max = 0 ;