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.

hkasthuri

Answered On : 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

TriVinDreamer

Answered On : Oct 27th, 2008

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

prakash_om

Answered On : 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

jjtharappel

Answered On : 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

jjtharappel

Answered On : Nov 24th, 2011

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

```CodeACCEPT WS-SYSIN-DATA FROM SYSIN
IF WS-SYSIN-NUM IS NUMERIC
COMPUTE WS-I = WS-SYSIN-NUM
IF WS-I > 9
PERFORM UNTIL WS-I < 10
COMPUTE WS-H = WS-I
COMPUTE WS-I = WS-H / 10
COMPUTE WS-J = WS-I * 10
COMPUTE WS-K = WS-H - WS-J
IF WS-K < WS-L
MOVE WS-K TO WS-L
END-IF
END-PERFORM
IF WS-I < WS-L
MOVE WS-I TO WS-L
END-IF
ELSE
MOVE WS-I TO WS-L
END-IF
DISPLAY "MINIMUM DIGIT OF NUMBER " WS-SYSIN-NUM " IS " WS-L
ELSE
DISPLAY "INPUT NUMBER NOT NUMERIC, PUT 10 DIGIT NUMBER"
END-IF
STOP RUN
```