Write a sub algorithm to find the smallest element from the given array. illustrate using an example
Answers
Answered by
6
1 create an array.
2 initalize the value of array.
3 create a variable smallest.
4 initalize the smallest variable with the array first element.
5 now check the array next element (after first ) with smallest if the next element of array is smaller than the initialize it in smallest else skip to other element comparison.
6 do 5 - step with all element of array in end you get smallest out of them.
example
int array[]={10,3,1}
int smallest=10; // intiallize first elment of array.
1.3<10 so smallest become . smallest=3.
2.1<3 so smallest become. smallest=1.
now element left to comparison so .
smallest value in array is 1.
Similar questions