* Help with Translation, please!
@ 1996-02-26 0:00 Robert Gelb
1996-02-27 0:00 ` Pascal OBRY
0 siblings, 1 reply; 3+ messages in thread
From: Robert Gelb @ 1996-02-26 0:00 UTC (permalink / raw)
I am having a hell of a time translating a little recursive factorial
program from C to Ada. Could some please help me. Below is the C code
that needs to be translated to ADA
#include <stdio.h>
int factorial(int);
int main() {
long f;
int number;
printf("\nPlease enter factorial number:");
scanf("%d", &number); /*get the factorial number*/
f = factorial(number); /*invoke factorial function*/
printf ("Result: %ld", f);
return 0;
}
int factorial(int n) {
int ReturnValue;
if (n > 1)
ReturnValue = n * factorial(n-1);
else
ReturnValue = 1;
return ReturnValue;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Help with Translation, please!
1996-02-26 0:00 Robert Gelb
@ 1996-02-27 0:00 ` Pascal OBRY
0 siblings, 0 replies; 3+ messages in thread
From: Pascal OBRY @ 1996-02-27 0:00 UTC (permalink / raw)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 876 bytes --]
Robert,
I think you are kidding. There is nothing difficult in your example. Did you
try to learn Ada :-) What are your dead line for this project :-)
Pascal.
--
--|------------------------------------------------------------
--| Pascal OBRY Team-Ada Member |
--| |
--| EDF-DER-IPN-SID- Ing�nierie des Syst�mes d'Informations |
--| |
--| Bureau G1-010 e-mail: Pascal.Obry@der.edfgdf.fr |
--| 1 Av G�n�ral de Gaulle voice : +33-1-47.65.50.91 |
--| 92141 Clamart CEDEX fax : +33-1-47.65.50.07 |
--| FRANCE |
--|------------------------------------------------------------
--| "The best way to travel is by means of imagination"
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Help with Translation, please!
[not found] ` <4h2gu9$hp6@watnews1.watson.ibm.com>
@ 1996-03-15 0:00 ` Robert I. Eachus
0 siblings, 0 replies; 3+ messages in thread
From: Robert I. Eachus @ 1996-03-15 0:00 UTC (permalink / raw)
In article <4hvvm2$ird@ds8.scri.fsu.edu> jac@ds8.scri.fsu.edu (Jim Carr) writes:
eachus@spectre.mitre.org (Robert I. Eachus) writes:
>
> .... The same holds for factorials. They can be generated
>exactly in (small) constant time and space. (Actually, if you are not
>using floating point, the time is proportional to the square of the
>length of the result...)
> Make up your mind. ;-)
> Constant or square? A loop is better than linear in the length.
It depends on whether you use a computation model where arithmetic
operations require constant time or require time proportional to the
length of the operands. In the case of factorial it matters.
> And your comment about a sqrt based method, if one exists, seems
> to ignore the extra time required -vs- multiplication. Anyway,
> my main application looks up log(n!) so its a moot point.
Well since no one took the challenge, how about an extra hint.
The ONE square root you need is the square root of five..
--
Robert I. Eachus
with Standard_Disclaimer;
use Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1996-03-15 0:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <4gvta2$531@ds8.scri.fsu.edu>
[not found] ` <4h2gu9$hp6@watnews1.watson.ibm.com>
1996-03-15 0:00 ` Help with Translation, please! Robert I. Eachus
1996-02-26 0:00 Robert Gelb
1996-02-27 0:00 ` Pascal OBRY
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox