Re: (part 4) Han from China answers your C questions,
- From: Kelsey Bjarnason <kelseyb@xxxxxxxxx>
- Date: Fri, 31 Oct 2008 06:36:31 -0700
[snips]
On Thu, 30 Oct 2008 15:46:04 +0100, George Orwell wrote:
Why is it wrong??(About n!)
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.
ISO C makes no assurances that the simplest "Hello, world" program will
ever actually produce an output and terminate; the system's I/O buffers
could wind up in a locked state and never allow the output.
If the lack of performance guarantees is a reason not to calculate n!, it
is also reason not to do *any* coding in C. Nor C++, Perl, Haskell or
any other language.
system("pause");
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.
Why not simply use puts( "Press enter to continue" ); getchar(); ?
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);
What this has to do with C, however...
.
- References:
- (part 4) Han from China answers your C questions,
- From: George Orwell
- (part 4) Han from China answers your C questions,
- Prev by Date: Re: a question abou "atoi"
- Next by Date: Re: (part 1) Han from China answers your C questions
- Previous by thread: (part 4) Han from China answers your C questions,
- Next by thread: (part 2) Han from China helps you with your killfile
- Index(es):