commit deletes
This commit is contained in:
parent
776bba907c
commit
372c577f83
233 changed files with 0 additions and 6724 deletions
|
|
@ -1,32 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
// we return a static buffer; caller wants it, caller copies it
|
||||
char * mid3(int n)
|
||||
{
|
||||
static char buf[32];
|
||||
int l;
|
||||
sprintf(buf, "%d", n > 0 ? n : -n);
|
||||
l = strlen(buf);
|
||||
if (l < 3 || !(l & 1)) return 0;
|
||||
l = l / 2 - 1;
|
||||
buf[l + 3] = 0;
|
||||
return buf + l;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int x[] = {123, 12345, 1234567, 987654321, 10001, -10001,
|
||||
-123, -100, 100, -12345, 1, 2, -1, -10, 2002, -2002, 0,
|
||||
1234567890};
|
||||
|
||||
int i;
|
||||
char *m;
|
||||
for (i = 0; i < sizeof(x)/sizeof(x[0]); i++) {
|
||||
if (!(m = mid3(x[i])))
|
||||
m = "error";
|
||||
printf("%d: %s\n", x[i], m);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
identification division.
|
||||
program-id. middle3.
|
||||
environment division.
|
||||
data division.
|
||||
working-storage section.
|
||||
01 num pic 9(9).
|
||||
88 num-too-small values are -99 thru 99.
|
||||
01 num-disp pic ---------9.
|
||||
|
||||
01 div pic 9(9).
|
||||
01 mod pic 9(9).
|
||||
01 mod-disp pic 9(3).
|
||||
|
||||
01 digit-counter pic 999.
|
||||
01 digit-div pic 9(9).
|
||||
88 no-more-digits value 0.
|
||||
01 digit-mod pic 9(9).
|
||||
88 is-even value 0.
|
||||
|
||||
01 multiplier pic 9(9).
|
||||
|
||||
01 value-items.
|
||||
05 filler pic s9(9) value 123.
|
||||
05 filler pic s9(9) value 12345.
|
||||
05 filler pic s9(9) value 1234567.
|
||||
05 filler pic s9(9) value 987654321.
|
||||
05 filler pic s9(9) value 10001.
|
||||
05 filler pic s9(9) value -10001.
|
||||
05 filler pic s9(9) value -123.
|
||||
05 filler pic s9(9) value -100.
|
||||
05 filler pic s9(9) value 100.
|
||||
05 filler pic s9(9) value -12345.
|
||||
05 filler pic s9(9) value 1.
|
||||
05 filler pic s9(9) value 2.
|
||||
05 filler pic s9(9) value -1.
|
||||
05 filler pic s9(9) value -10.
|
||||
05 filler pic s9(9) value 2002.
|
||||
05 filler pic s9(9) value -2002.
|
||||
05 filler pic s9(9) value 0.
|
||||
|
||||
01 value-array redefines value-items.
|
||||
05 items pic s9(9) occurs 17 times indexed by item.
|
||||
|
||||
01 result pic x(20).
|
||||
|
||||
procedure division.
|
||||
10-main.
|
||||
perform with test after varying item from 1 by 1 until items(item) = 0
|
||||
move items(item) to num
|
||||
move items(item) to num-disp
|
||||
perform 20-check
|
||||
display num-disp " --> " result
|
||||
end-perform.
|
||||
stop run.
|
||||
|
||||
20-check.
|
||||
if num-too-small
|
||||
move "Number too small" to result
|
||||
exit paragraph
|
||||
end-if.
|
||||
|
||||
perform 30-count-digits.
|
||||
divide digit-counter by 2 giving digit-div remainder digit-mod.
|
||||
if is-even
|
||||
move "Even number of digits" to result
|
||||
exit paragraph
|
||||
end-if.
|
||||
|
||||
*> if digit-counter is 5, mul by 10
|
||||
*> if digit-counter is 7, mul by 100
|
||||
*> if digit-counter is 9, mul by 1000
|
||||
|
||||
if digit-counter > 3
|
||||
compute multiplier rounded = 10 ** (((digit-counter - 5) / 2) + 1)
|
||||
divide num by multiplier giving num
|
||||
divide num by 1000 giving div remainder mod
|
||||
move mod to mod-disp
|
||||
else
|
||||
move num to mod-disp
|
||||
end-if.
|
||||
move mod-disp to result.
|
||||
exit paragraph.
|
||||
|
||||
30-count-digits.
|
||||
move zeroes to digit-counter.
|
||||
move num to digit-div.
|
||||
perform with test before until no-more-digits
|
||||
divide digit-div by 10 giving digit-div remainder digit-mod
|
||||
add 1 to digit-counter
|
||||
end-perform.
|
||||
exit paragraph.
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/* REXX ***************************************************************
|
||||
* 03.02.2013 Walter Pachl
|
||||
**********************************************************************/
|
||||
sl='123 12345 1234567 987654321 10001 -10001 -123 -100 100 -12345',
|
||||
'2 -1 -10 2002 -2002 0 abc 1e3 -17e-3'
|
||||
Do While sl<>'' /* loop through test values */
|
||||
Parse Var sl s sl /* pick next value */
|
||||
Call mid3 s /* test it */
|
||||
End
|
||||
Exit
|
||||
mid3: Procedure
|
||||
Parse arg d /* take the argument */
|
||||
Select /* first test for valid input */
|
||||
When datatype(d)<>'NUM' Then Call error 'not a number'
|
||||
When pos('E',translate(d))>0 Then Call error 'not just digits'
|
||||
When length(abs(d))<3 Then Call error 'less than 3 digits'
|
||||
When length(abs(d))//2<>1 Then Call error 'not an odd number of digits'
|
||||
Otherwise Do /* input is ok */
|
||||
dx=abs(d) /* get rid of optional sign */
|
||||
ld=length(dx) /* length of digit string */
|
||||
z=(ld-3)/2 /* number of digits to cut */
|
||||
Say left(d,12) '->' substr(dx,z+1,3) /* show middle 3 digits */
|
||||
End
|
||||
End
|
||||
Return
|
||||
error:
|
||||
Say left(d,12) '->' arg(1) /* tell about the problem */
|
||||
Return
|
||||
Loading…
Add table
Add a link
Reference in a new issue