Maximum of array

Back to General discussions forum

mewallace     2018-01-03 13:25:46

Hi,I don't know how to input a line of numbers without knowing the number of the input numbers. Can you help me?

Quandray     2018-01-03 14:13:44
User avatar

With this problem, there are always 300 numbers.
for(i=0;i<298;i++) scanf("%d ",&a[i]); will only read 298.
You probably want to change
int c=0,i,d=0;
to
int c=-999999999,i,d=999999999;

mewallace     2018-01-09 02:58:12

include<stdio.h>

include<string.h>

int main() { int a[299]; int c=-999999999,i,d=999999999; for(i=0;i<298;i++) { scanf("%d",&a[i]); if(a[i]>c) c=a[i]; if(a[i]<d); d=a[i]; } printf("%d %d",c,d); return 0; }

mewallace     2018-01-09 03:13:12

Yeah, but my answer is still wrong. Can someone give me a correct example?

Quandray     2018-01-09 07:23:04
User avatar

There are 300 numbers. Why does your "a[299]" have only 299 elements and why does your for loop (and scanf) only process 298 numbers?

MostMoodee     2018-03-13 22:16:31

aaaaaaaaaaaaaaaaaaaaaaaaaaa

MostMoodee     2018-03-13 22:16:33

aaaaaaaaaaaaaaaaaaaaaaaaaaa

Please login and solve 5 problems to be able to post at forum