Computer Science, asked by FutureFlash, 4 days ago

write an algorithm to find out smallest and largest among 3 elements? ​

Answers

Answered by ArchBTW
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 SaurabhJacob
1

The algorithm for the given problem is,

  1. INPUT a, b, c
  2. SET minimum = a, maximum = a
  3. IF b < minimum THEN
  4.     minimum = b  
  5. IF c < minimum THEN
  6.     minimum = c
  7. IF b > maximum THEN
  8.     maximum= b
  9. IF c > maximum THEN
  10.     maximum = c
  11. 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