Skip to content

samkitjain4916/Largest-and-smallest

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Largest-and-smallest

This is a c++ program to find the largest and smallest number in an array.

Explanation –

  1. The user is initially asked to enter the size of the array and it is stored in the variable ‘n’.
  2. An array ‘arr’ of data type integer is declared with size 10.
  3. Elements of the array are asked to enter and stored in ‘arr’ using a for loop
  4. The value at index 0 of arr is assigned to the variable ‘max’.
  5. Using a for loop and initializing ‘i’ as 0, the largest element is found.
  6. If max is less than arr[i], then value of arr[i] is assigned to max. i is incremented in every iteration.
  7. The loop continues till ‘i’ is less than ‘n’.
  8. Similarly, the smallest element is found.
  9. The value at index 0 of arr is assigned to the variable ‘min’.
  10. Using a for loop the smallest element is assigned to min.
  11. The result is then printed.

About

C++ program to find the largest and smallest number in an array.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 100.0%