C++ program to find the largest and second-largest numbers present in an array along with their location index on the array. This program first find the largest number by going through all the numbers in the array. It stores the index of the largest number on the variable pos1 and largest number is the largest variable. A second for loop is applied, which also check for the largest number. When it hits on the largest found by the first loop, it is bypassed using a continue statement and hence will get the second-largest number.
#include <iostream> #include <conio.h> using namespace std; void main() { int a[10], i, largest = 0, second_largest = 0, pos1, pos2; int n; cout << "Enter Number of elements :"; cin >> n; for (i = 0; i < n; ++i) { cout << "n Enter " << (i + 1) << "th Element :"; cin >> a[i]; } //Finding Largest for (i = 0; i < 10; ++i) { if (a[i] > largest) { largest = a[i]; pos1 = i; } } //finding second largset for (i = 0; i < 10; ++i) { if (a[i] > second_largest) { if (a[i] == largest) continue; //Ignoring largest in order to get second largest second_largest = a[i]; pos2 = i; } } cout << "nn Largest Number :" << largest << " at position " << (pos1 + 1); cout << "nn Second Largest Number :" << second_largest << " at position " << (pos2 + 1); getch(); return; }
*Compiled using Visual Studio
… [Trackback]
[…] Read More to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Read More Info here to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Read More Information here on that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Read More Information here to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Info on that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Information to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Read More Information here to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Read More Info here to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Find More Info here on that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Find More here to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Read More to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Find More on to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Here you will find 52940 more Information on that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Info on that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Read More to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Read More to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Find More Information here on that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Here you can find 6780 more Information to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Information on that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Info on that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Here you will find 5746 more Information to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Read More Info here to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Read More on to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] There you can find 47640 more Information to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Find More Info here on that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Information on that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] There you will find 80703 additional Information on that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Info to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Read More Info here to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Read More Info here to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Find More Info here on that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Find More Info here on that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Find More here to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Find More to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] There you will find 88839 more Info to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] There you can find 32241 additional Info to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Find More on that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Find More Info here on that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
… [Trackback]
[…] Read More to that Topic: genuinecoder.com/cpp-program-find-largest-and-second-largest-number-array-html/ […]
acheter kamagra bonne prix pharmacie en ligne
générique kamagra capsules comparaison de prix
free enclomiphene prices
cheapest buy enclomiphene generic low price
buy androxal generic london
ordering androxal low price
order dutasteride spain over the counter
ordering dutasteride generic europe
purchase flexeril cyclobenzaprine cheap canada pharmacy
order flexeril cyclobenzaprine cheap online pharmacy
how to buy fildena usa drugstore
cheapest buy fildena generic switzerland
how to buy gabapentin purchase online canada
cheap gabapentin purchase tablets
cheapest buy itraconazole cheap to buy online
ordering itraconazole cheap uk
online order staxyn canada mail order
buying staxyn lowest cost pharmacy
cheap avodart uk online pharmacy
how to order avodart generic form
how to buy rifaximin generic available in united states
how to buy rifaximin australia generic online
buying xifaxan no prescription needed
how to order xifaxan cheap buy online no prescription
kamagra v mexiku bez lテゥkaナ冱kテゥho pナ册dpisu
kamagra sobotnテュ doruト稿nテュ