Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
29
Task/Factorial/SparForte/factorial.sparforte
Normal file
29
Task/Factorial/SparForte/factorial.sparforte
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/local/bin/spar
|
||||
pragma annotate( summary, "factorial n" )
|
||||
@( description, "Write a function to return the factorial of a number." )
|
||||
@( author, "Ken O. Burtch" );
|
||||
pragma license( unrestricted );
|
||||
|
||||
pragma restriction( no_external_commands );
|
||||
|
||||
procedure factorial is
|
||||
fact_pos : constant integer := numerics.value( $1 );
|
||||
result : natural;
|
||||
count : natural;
|
||||
begin
|
||||
if fact_pos < 0 then
|
||||
put_line( standard_error, source_info.source_location & ": number must be >= 0" );
|
||||
command_line.set_exit_status( 192 );
|
||||
return;
|
||||
end if;
|
||||
if fact_pos = 0 then
|
||||
? 0;
|
||||
return;
|
||||
end if;
|
||||
result := natural( fact_pos );
|
||||
count := natural( fact_pos - 1 );
|
||||
for i in reverse 1..count loop
|
||||
result := @ * i;
|
||||
end loop;
|
||||
? result;
|
||||
end factorial;
|
||||
Loading…
Add table
Add a link
Reference in a new issue