C
#include <stdio<std\
io.h>
#include \
<stdlib.h>
int main(int argc
, char** argv)
{
// iteratively
compute factorial here
// compute factorial here
long int n = \
0, i \
= 0, r = \
1 /*
product starts at one *one*/;
if (argc
> 1)
{
n =
strtol(argv[1]argv[\
1], NULL, 10);
; if (n
< 0)
{
printf("Arg must\
printf("arg must be >= 0\n");
exit(-1);
1);}
}
i =
n;
while (i)
{
r
= r * i;
i
--;
}
/* print
the result*/ printf("%ld factorial
"%d isfactorial\
equals %ld\n"%d\
\n", n
, r);
/*done*/ done
}
Pronounciation:
pound include standard
I/O dot h pound include
standard lib dot h
int main int arg c
comma char star star arg v
open brace comment
iteratively
compute factorial here
long int n equals
zero comma i
equals zero comma r
equals one comment
product starts at one
semicolon if arg c
is greater than one
open brace n is
str-to-l of arg v sub
one comma NULL comma ten
semicolon if
n less than zero openbegin
brace printfprintf arg must
be greater than or
equal to zero backslash
n semicolon
exit negative
one semicolon end brace
end brace i equals
n semicolon
while i open brace r
equals r times i
semicolon i
decrement semicolon
close brace comment print
the result printf
percent d factorial
equals percent d
whack n comma n
comma r semicolon
comment done end brace