GeekInterview.com
Series: Subject: Topic:
Question: 43 of 51

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.

Asked by: Interview Candidate | Asked on: Oct 11th, 2007
Showing Answers 1 - 5 of 5 Answers
hkasthuri

Answered On : Nov 22nd, 2007

View all answers by hkasthuri

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

  
Login to rate this answer.
TriVinDreamer

Answered On : Oct 27th, 2008

View all answers by TriVinDreamer

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;
}

  
Login to rate this answer.
prakash_om

Answered On : Jul 6th, 2010

View all answers by prakash_om

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
         

  
Login to rate this answer.
jjtharappel

Answered On : Nov 23rd, 2011

View all answers by jjtharappel

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

  
Login to rate this answer.
jjtharappel

Answered On : Nov 24th, 2011

View all answers by jjtharappel

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.  

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.