/* Program for finding first two LARGEST number from 'n' entered numbers. */ #include <iostream> using namespace std; int main() { int count, large1, large2, num; cout << "How many numbers do u want to enter?\t"; cin >> count; cout << "Enter number?\t"; cin >> num; large1 = num; large2 = 0; while (count>1) { cout << "Enter number?\t"; cin >> num; if (num > large1) { large2 = large1; large1 = num; } else if (num > large2) large2 = num; count--; } cout << "\nLARGEST number is \t" << large1 << endl; cout << "2nd LARGEST number is \t" << large2 << endl; return 0; } /* Program for finding first two SMALLEST number from 'n' entered numbers. */ #include <iostream> using namespace std; int main() { int count, small1, small2, num; cout << "How many numbers do u want to enter?\t"; cin >> count; cout << "Enter number?\t"; cin >> num; small1 = num; small2 = 2147483647; while (count>1) { cout << "Enter number?\t"; cin >> num; if (num < small1) { small2 = small1; small1 = num; } else if (num < small2) small2 = num; count--; } cout << "\nSMALLEST number is \t" << small1 << endl; cout << "2nd SMALLEST number is \t" << small2 << endl; return 0; } /* Program for finding first two LARGEST or SMALLEST number from 'n' entered numbers. */ #include <iostream> using namespace std; int main() { int count, large1, large2, small1, small2, num; cout << "How many numbers do u want to enter?\t"; cin >> count; cout << "Enter number?\t"; cin >> num; small1 = num; small2 = 2147483647; large1 = num; large2 = 0; while (count>1) { cout << "Enter number?\t"; cin >> num; if (num > large1) { large2 = large1; large1 = num; } else if (num > large2) large2 = num; if (num < small1) { small2 = small1; small1 = num; } else if (num < small2) small2 = num; count--; } cout << "\nLARGEST number is \t" << large1 << endl; cout << "2nd LARGEST number is \t" << large2 << endl; cout << "\nSMALLEST number is \t" << small1 << endl; cout << "2nd SMALLEST number is \t" << small2 << endl; return 0; }
This blog is about coding in some commonly used "High Level Languages" like C, C++, Java etc. At first, I will post here basic programs written in C++ language only.
Thursday, November 27, 2014
C++ Program for finding first two LARGEST or SMALLEST number from 'n' Entered numbers
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment