Back to General discussions forum
Hi,I don't know how to input a line of numbers without knowing the number of the input numbers. Can you help me?
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;
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; }
Yeah, but my answer is still wrong. Can someone give me a correct example?
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?
aaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa