Created
August 7, 2018 00:42
-
-
Save Elsayegh/a067908e3bda7fa8f96472ae2b09b6a7 to your computer and use it in GitHub Desktop.
C++ 7-1 Finding Largest and Smallest Array Values in Array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*Write a program that lets the user enter 10 values into an array. The program should then display the largest and smallest values | |
| stored in the array. */ | |
| #include <iostream> | |
| #include <conio.h> | |
| #include <ctime> | |
| #include <iomanip> | |
| #include <cstdlib> | |
| #include <fstream> | |
| #include <string> | |
| #include <math.h> | |
| using namespace std; | |
| int main() { | |
| int numbers[10]; | |
| int largest = 0; | |
| int smallest = 0; | |
| int tmp = 0; | |
| for (int i = 0; i <= 9; i++) { | |
| cout << "Please enter number " << i + 1 << ": " << endl; | |
| cin >> numbers[i]; | |
| } | |
| smallest = numbers[0]; | |
| largest = numbers[0]; | |
| for (int i = 1; i <= 9; i++) { | |
| if (numbers[i] < smallest) | |
| smallest = numbers[i]; | |
| if (numbers[i] > largest) | |
| largest = numbers[i]; | |
| } | |
| cout << "Largest Value is: " << largest << endl; | |
| cout << "Smallest Value is: " << smallest << endl; | |
| _getch(); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment