algorithm to find smallest two numbers from list
how many no.s are given??
its a sequence of numbers from 1 to n distinct
use an array to store this numbers. compare the first element of the array with the rest. if any no becomes smaller than the first no. while checking then replace the first no with the smaller one and continue the checking the the new no. at last you will get the smallest no. at the first position.
write algo that returns index of the first item that is less than its predecessor in sequence S1 ............. Sn, if s in nondecreasing order that algo returns the value 0
do u know C language?
ya i know
do u want the algo?
yes
take c as a array. c={1st , 2nd,........nth} for (i=0:1<n:i++) { if (c(0)<=c(i)) c(0)=c(i); } printf("\n %f ",c(0));
i think it works
thanks i wll try ok
Join our real-time social learning platform and learn together with your friends!