#include <iostream>
using namespace std;
int maxint(int *array, int size){
int index, temp_max = INT_MIN;
for(int i = 0; i < size; i++){
if(array[i] > temp_max){
temp_max = array[i];
index = i;
}
}
return index;
}
int main()
{
int *array, size = 0;
cout<<"Enter the size of the array: "; cin>>size;
cout<<"Input the elements\n";
array = new int[size];
for(int i = 0; i < size; i++){
cin>>array[i];
}
int index = maxint(array, size);
cout<<"Largest element: "<<array[index]<<" Index: "<<index<<endl;
return 0;
}
Comments
Leave a comment