+ 1
Help me pls, can't figure it out.
Find bigest number. int main() { int n; cin>>n; //size of the array //your code goes here int *nums = new int[n]; int max = nums[0]; nums [0] =n; for(int i=0; i<n; i++) { if(nums[i]>max) max = nums[i]; } cout << max; delete []nums; return 0; } Why it is only looking for first number?
7 ответов
0
Thanks, did't know about max = *max_element(nums, nums + n);
just could't figure it how to determine it.
0
And by the way, still haven't learned about #include <algorithm>, so here was a mistake too, just did not include it before.
- 1
Initialize max with 0 perhaps it should be the maximum number in the array .If zero not the max so swap it with the true maximum nums .
int max = 0;