Arrays-max value in array quest

Take as input N, the size of array. Take N more inputs and store that in an array. Write a function which returns the maximum value in the array. Print the value returned.

1.It reads a number N.

2.Take Another N numbers as input and store them in an Array.

3.calculate the max value in the array and return that value.

this is my code 2 test cases are passed other two are not successfull (1st and 3rd) plz help
#include
int main() {
int N;
std::cin>>N;
if(N>=0)
{int arr[N];
int max;
for(int i=0;i<=N;i++){
std::cin>>arr[i];
if(arr[i]>-1000000000 && arr[i]<1000000000){
max=arr[0];
if(arr[i]>max)
{
max==arr[i];
}

}}
std::cout<<max;
}
return 0;
}

@Anoushka_1805 Hey Anoushka you did a couple of mistake at

  1. max==arr[i]
  2. for(int i=0 ; i<=N ; i++)
    got it?

first for an N element array index is n-1 as we also consider 0
so for loop will be upto n-1 only that is for i=0;i<N

also u are doing max==a[i] this is a equal to operator which check the two value equal or not
but here u have to asiign the value of a[i] to max therefore u have to use assignment operator
max=a[i]

it is still giving error in two test cases
#include
int main() {
int N;
std::cin>>N;
if(N>=0)
{int arr[N];
int max;
for(int i=0;i<=N-1;i++){
std::cin>>arr[i];
if(arr[i]>-1000000000 && arr[i]<1000000000){
max=arr[0];
if(arr[i]>=max)
{
max=arr[i];
}

}}
std::cout<<max;
}
return 0;
}

u r always declaring max=a[0] so all the values are comparing with a[0]
for eg
1 5 3 4 2
first max=a[0]
then 5>max so max=5
but second time when loop run u are again saying max=a[0]
so here max became 1 and now 3 is comparing with 1 which is an amiguity

try once again and if not get it
check this

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.