Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

find second largest element in array w/o using sorting
techniques? use onle one for loop.

Answer Posted / alam cse-35 bangladesh univers

#include<iostream>
using namespace std;
int main()
{
int i,a[]={121,104,105,205,6,25,80,77,120},max=0,second_max=0;
for(i=0;i<=8;i++)
{
if(a[i]>max)
{
max=a[i];
}
}
for(i=0;i<=8;i++)
{
if(a[i]!=max)
{
if(a[i]>second_max)
{
second_max=a[i];
}
}
}

cout<<"Second Highest Value:"<<second_max<<endl;
cout<<"Maximum Value:"<<max;
return 0;
}

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is there any possibility to create customized header file with c programming language?

1072


How do I read the arrow keys? What about function keys?

1094


Are the variables argc and argv are local to main?

1324


Write a program to print "hello world" without using a semicolon?

1071


What is the process to create increment and decrement stamen in c?

1062


Write a programme using structure that create a record of students. The user allow to add a record and delete a record and also show the records in ascending order.

2100


a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list

1070


What is a newline escape sequence?

1111


What is function and its example?

1232


Why is c not oop?

984


All technical questions

1998


What is "Duff's Device"?

1175


What is type qualifiers?

1142


Place the #include statement must be written in the program?

1048


what is the format specifier for printing a pointer value?

1031