how to find a factorial of a given number through command line argument
how to find a factorial of a given number through command line argument
can anyone tell me a code to find factorial of a given number throughcommand line argument
How to ask a decent question.
http://www.catb.org/~esr/faqs/smart-questions.html
If you were expecting an answer on a plate, it doesn't work like that.
Attention and help on our part depends on some effort on your part.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Well, first you need to learn to use the command line arguments, this is actually not very hard at all, try to google for some tutorials on how to use argc and argv.
Then you just have to write a function that will find the factorial of a given number. This is also not very hard, if you know how to do it on paper it should be a breeze, also, the web is littered with tutorial on recursion that uses factorial calculation as an example.
Be cautious though, if the user inputs something like 160, the resulting factorial will undoubtedly cause an overflow, so check the input before going on.
Also, the command line arguments are an array of chars, so you will most likely need to convert it to a number for your function (Unless ofcourse you write it so it will accept a char), look into atoi() for this, or maybe strtol().
Here's one on this very site. http://www.cprogramming.com/tutorial/c/lesson14.htmlWell, first you need to learn to use the command line arguments, this is actually not very hard at all, try to google for some tutorials on how to use argc and argv.
There's a link for every problem. http://faq.cprogramming.com/cgi-bin/...043284385#opt3Also, the command line arguments are an array of chars, so you will most likely need to convert it to a number for your function (Unless ofcourse you write it so it will accept a char), look into atoi() for this, or maybe strtol().
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.