Why is it wrong??(About n!)
Quote:
upyzl said:
I want to calculate n!,and my C code is as follows:
This is off-topic for this newsgroup. ISO C makes
no assurances that your target processor (if there is
a processor) can calculate n! in a reasonable length
of time. It's best not to make any assumptions.
That said, I'll try my best to help you out.
<snip>
Not every system has a 'pause' command. To increase the
portability of your program /somewhat/, perhaps add
pause() after your system() call so that on systems
with the typical pause() function, you can send your program
a signal to resume. Actually, you may want to investigate
possible flow-control mechanisms.
Now, it's probable that someone has designed a far more
efficient factorial function than your one, and perhaps
they've even supplied you with a 'factorial' command. Since
using such a 'factorial' command directly from the command
line would deprive you of valuable programming experience,
I recommend building up a little command string and then
calling system(). Something like this:
snprintf(command, sizeof command, "factorial %lu", n);
system(command);
That way, you get the benefit of the efficient factorial
function, which may have even been implemented with a built-in
gamma function, a great bonus if ever you want to extend
your code out of N.
Yours,
Han from China
Il mittente di questo messaggio|The sender address of this
non corrisponde ad un utente |message is not related to a real
reale ma all'indirizzo fittizio|person but to a fake address of an
di un sistema anonimizzatore |anonymous system
Per maggiori informazioni |For more info
https://www.mixmaster.it