T.R | Title | User | Personal Name | Date | Lines |
---|
1445.1 | oops, I hear mom calling | VMSDEV::HALLYB | The Smart Money was on Goliath | Tue May 14 1991 18:14 | 7 |
| Is this a math problem or a C problem?
(Meaning is something clever about stdio involved, or is that just to
level the playing field beteween C implementations that automatically
include stdio).
John
|
1445.2 | all over but the programming? :-) | GUESS::DERAMO | Be excellent to each other. | Tue May 14 1991 21:43 | 10 |
| The third differences are constant, so the n-th member of
the sequence can be written as a cubic in n. Start
counting with n=0 and you see x and x-1 both divide the
cubic. The last factor goes ?,?,1,1.5,2,2.5,3,... and so
must be x/2. So the sequence is
2
n (n-1) / 2 n = 0,1,2,3,4,5,6,7,8,9
Dan
|
1445.3 | by the way, the #include is superfluous here | GUESS::DERAMO | Be excellent to each other. | Wed May 15 1991 08:56 | 18 |
| $ cat foo.c
#include <stdio.h>
main(){int i;for(i=0;i<10;i++)printf("%d\n",i*i*(i-1)/2);}
$ wc foo.c
2 4 78 foo.c
$ cc foo.c
$ a.out
0
0
2
9
24
50
90
147
224
324
$
|
1445.4 | bit shorter still.. | SMAUG::ABBASI | | Wed May 15 1991 15:54 | 4 |
| #include <stdio.h>
i;m(){for(i=0;i<10;i++)printf("%d\n",i*i*(i-1)/2);}
saves 7 bytes :-)
|
1445.5 | need main, not m (DECstation 3100, ULTRIX V4.0) | GUESS::DERAMO | Be excellent to each other. | Wed May 15 1991 18:04 | 18 |
| re .4,
$ cat > foo.c
#include <stdio.h>
i;m(){for(i=0;i<10;i++)printf("%d\n",i*i*(i-1)/2);}
$ cc foo.c
ld:
Undefined:
main
$ wc foo.c
2 3 71 foo.c
$
But it didn't work. :-) I had tried "i" instead of "int i"
inside the function but that didn't work; putting the "i"
outside the function apparently does, though.
Dan
|
1445.6 | A mathematical code bum | SHRIMP::LARY | Spukhafte Fernwirkungen | Wed May 15 1991 23:39 | 5 |
| #include <stdio.h>
i,s;m(){for(s=i=0;i<10;s+=i++)printf("%d\n",i*s);}
saves another byte from .4...
|
1445.7 | reminds me of PDP-8 coding daze | ALLVAX::JROTH | I know he moves along the piers | Thu May 16 1991 00:12 | 19 |
| vitus % cat small.c
i,s;m(){for(;i<10;s+=i++)printf("%d\n",i*s);}
vitus % wc small.c
1 1 46 small.c
vitus % cc -o small -Dm=main small.c
vitus % small
0
0
2
9
24
50
90
147
224
324
vitus %
- Jim
|
1445.8 | two characters? | GUESS::DERAMO | Be excellent to each other. | Thu May 16 1991 00:24 | 27 |
| When I saw .6 I asked if on VMS the first function was
called if main was not defined. But in .7 you compile
with the flag -Dm=main redefining m to be main.
By that logic why not just do
% cat small.c
A
% wc small.c
1 1 2 small.c
% cc -D'A=main(){int i;for(i=0;i<10;i++)printf("%d\n",i*i*(i-1)/2);}' small.c
% a.out
0
0
2
9
24
50
90
147
224
324
%
:-)
Dan
|
1445.9 | looks like VAXC/vms is different that your compiler | SMAUG::ABBASI | | Thu May 16 1991 10:32 | 6 |
| ref .5 (Dan)
by default if you put a variable outside the function scope it is defaulted
as int type. at least on VMS implementation of VAXC.
also you dont have to use "main" as name of you main function.. again
on VAX VMS at least.
/naser
|