Hello to all frndz! i want to write a program in which i have stored some integer elements in an array and i want that my program searches for the largest integer and displays it. for example if i have some integers in my array like 23, 38, 81, 12. then my program should display "Largest integer is 81". I have wrote code for this program but it gives wrong output. the code for my program is as follows:
#include<iostream.h>
main()
{
int arr[4]={23,38, 81,12};
int i; // counter variable
for(i=0;i<=4;i++)
{
if(arr[i]>(arr[i+1]))
{
cout<<"largest integer is"<<arr[i]<<endl;
}
else
cout<<"largest integer is "<<arr[i+1]<<endl;
}
system("pause");
}