Pivot element in rotated sorted array

is this code is correct or not?

PROGRAM

///FIND THE MAXIMUM ELEMENT IN ROTATED SORTED ARRAY USING binarysearch
#include
using namespace std;
int findmax(int arr[],int start,int ends)
{
while(start <= ends)
{
int mid = (start + ends)/2;
if(arr[mid]>arr[mid+1])
return mid;
else if(arr[mid] < arr[mid-1])
return (mid-1);
else if(arr[mid] > arr[ends])
start = mid + 1;
else if(arr[start] > arr[mid])
ends = mid - 1;
}
}
int main()
{
int n;
cout<<“Enter value\n”;
cin>>n;
int arr[n];
cout<<“Enter “<<n<<” values\n”;
for(int i=0;i<n;i++)
cin>>arr[i];

int start = 0;
int ends = n-1;
int pivot = findmax(arr,start,ends);
cout<<arr[pivot]<<endl;

return 0;
}

Hey, your code is working fine but in this problem you are supposed to print the index of pivot element not the pivot element itself.