write an algorithm to find out smallest and largest among 3 elements?
Answers
Answered by
2
Answer:
This is how I will solve the problem:
Create an array of 3 integers (or more if you are willing to)
Create a variable named max (int) and set it to the first value of the array (through int max = arr[0]).
Run a loop till the size of the array
Check if the value of arr[i] is bigger then the previous one
if yes then change the value to arr[i]
if not then start going ahead.
So this will return the biggest integer/float in an array.
Hope it helps :)
Please mark it as the brainliest
Answered by
1
The algorithm for the given problem is,
- INPUT a, b, c
- SET minimum = a, maximum = a
- IF b < minimum THEN
- minimum = b
- IF c < minimum THEN
- minimum = c
- IF b > maximum THEN
- maximum= b
- IF c > maximum THEN
- maximum = c
- PRINT minimum, maximum
- The above algorithm is taking input in a, b, and c variables.
- Then the assumed minimum and maximum are stored in respective variables.
- After that, if's condition is checking for the minimum and maximum.
- Finally, the evaluated value of minimum and maximum is printed.
Similar questions