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.
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.
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.
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.
The one I posted on Nov23 will not sork. A slight modification. Below is the working code
Code
ACCEPT 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
Login to rate this answer.