You can find quality tech news,tricks,study materials etc contact me:facebook.com/ashwin.sunilkumar
Support Me...........
Please support me by giving donation
contact: aswinavofficial@gmail.com
Total Pageviews
Monday, September 1, 2014
C++ Program to find the second largest value in a sequence of n numbers
/* Program to find the second largest value in a sequence of n numbers */
#include
using namespace std;
int main() {
int x[10];
int largest, secondLargest;
cout << "Enter 10 random integers..." << endl;
for (int i=1; i<=10; i++) {
cout << "Enter value " << i << ": ";
cin >> x[i-1];
}
largest = secondLargest = x[0];
for (int i=0; i<10; i++)
if (x[i]>largest) {
secondLargest = largest;
largest = x[i];
}
cout << "This is the array... " << endl << " [ ";
for (int i=0; i<10; i++) {
cout << x[i] << " ";
}
cout << "] " << endl;
cout << "Second largest value is ";
cout << secondLargest << endl;
return 0;
}
// aiuto
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment