Advertisement
Primitiv0

Highest of 5 Numbers

Sep 10th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;//for cout and cin
  3. int main()
  4. {
  5. int a[5], greatest_so_far;
  6. cout << "Enter 5 numbers\n";
  7. for (int i = 0; i<5; i++)
  8. {
  9. cin >> a[i];
  10. }
  11. greatest_so_far = a[0];
  12. for (int i = 0; i < 5; i++)
  13. {
  14. if (a[i] > greatest_so_far)
  15. {
  16. greatest_so_far = a[i];//storing current greatest no.
  17. }
  18. }
  19. cout << "\nGreatest number is: " << greatest_so_far<<endl;
  20. system("pause");// to stop console window to see output
  21. return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement