Write an algorithm to find the minimum of numbers where N is any arbitary natural number. N is given to you by the user as the first value.

Showing Answers 1 - 15 of 15 Answers

hkasthuri

  • Nov 22nd, 2007
 

Algorithm smallestnumber
Input : N, any arbitary natural number within which the smallest number should be found
Output : Smallest number

Min <- I0
While I < N do
    if I < Min then min <- I
    Increment I by 1
Loop
return Min

  Was this answer useful?  Yes

N is given to you by the user as the first value.


Solution

Input:: N
Output:: min

int temp = N;
int digit;
int min = 10;
while(temp>0){
    digit = temp%10; // Find the last digit.
    if(min>digit) min = digit;
    temp = temp/10;
}

  Was this answer useful?  Yes

prakash_om

  • Jul 6th, 2010
 

Algorithm: Minimum of n numbers
Intput: a[1...n] an array of integers
Output: Minimum number

Step1:        Minimum=a[1]
Step2:        For i=1 to n do
Step3:        if(a[i]<Minimum)
Step4:        Minimum=a[i]
Step5:        return Minimum
         

  Was this answer useful?  Yes

jjtharappel

  • Nov 23rd, 2011
 

I = N / 10
J = I * 10
K = N - J
min_num = K

If I > 10
Do while I < 10
N = I
I = N / 10
j = I * 10
K = N - J
if K < min_num
min_num = K
end-if
end-do

Prinf "Minimum number is " min_num
Return

  Was this answer useful?  Yes

jjtharappel

  • Nov 24th, 2011
 

The one I posted on Nov23 will not sork. A slight modification. Below is the working code

Code
  1. ACCEPT WS-SYSIN-DATA FROM SYSIN      

  2. IF WS-SYSIN-NUM IS NUMERIC            

  3.    COMPUTE WS-I = WS-SYSIN-NUM        

  4.    IF WS-I > 9                        

  5.       PERFORM UNTIL WS-I < 10        

  6.          COMPUTE WS-H = WS-I          

  7.          COMPUTE WS-I = WS-H / 10    

  8.          COMPUTE WS-J = WS-I * 10    

  9.          COMPUTE WS-K = WS-H - WS-J  

  10.          IF WS-K < WS-L              

  11.             MOVE WS-K TO WS-L        

  12.          END-IF                      

  13.       END-PERFORM                    

  14.       IF WS-I < WS-L                  

  15.          MOVE WS-I TO WS-L            

  16.       END-IF                          

  17.    ELSE                              

  18.       MOVE WS-I TO WS-L              

  19.    END-IF                                                                              

  20.    DISPLAY "MINIMUM DIGIT OF NUMBER " WS-SYSIN-NUM " IS " WS-L

  21.  ELSE                                                        

  22.    DISPLAY "INPUT NUMBER NOT NUMERIC, PUT 10 DIGIT NUMBER"    

  23.  END-IF                                                      

  24.  STOP RUN                                                    

  25.  


  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions