Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
suppose i have found out the factorial of 2000. then if i have to find out the square root of the large factorial..then what to do?? can some one plzz frwd the algo for it..i think it might be newton raphson method.
Posted
Comments
nv3 22-Oct-12 16:08pm    
For one, people in this forum mostly find it annoying if a question is asked in mobile phone speak. If you want people to invest some time in helping you, you should have the courtesy to write in full sentences.

And second, your question looks like you got some homework which you try to avoid by having others do it for you. Not only would that counteract the idea of your homework in the first place, it would keep you from making progress. Most people here don't want that to happen.

If your question is not homework, then show us which steps you have tried on your own and where you got stuck. You haven't tried anything yet? Why do you think other people would invest their time then?

So: Try do come up with a couple of ideas yourself and when you got stuck, let us know exactly where and why. That way your success rate in this forum (and probably in general) will be significantly higher. And, believe me, it can be fun, too!

And: Yes, I do know the answer to this problem.

If you know the method name then why not try this[^] to start with?
 
Share this answer
 
Comments
decodererror2345 22-Oct-12 13:19pm    
if u know the answer then plzz let me know as i am nt getting way to implement it..as in this method i have to take xpower(n) in which x is the factorial of 2000
Richard MacCutchan 22-Oct-12 14:00pm    
Follow the link I gave you and start reading how Newton Raphson works.
If you know that you will be taking the square root of the result of the factorial function, just implement a function that directly computes the square root of factorial:

since factorial(n) is the product of the integers from 2 to n
square root of factorial(n) is the product of the square root of each of those integers from 2 to n

or, more efficient:

return Math.Pow(factorial(n), 0.5) (assuming factorial(n) is type double)

if your factorial(n) is returning BigInteger, then use Math.Exp(Math.BigInteger(factorial(n))/2.0)

Edit: I forgot that you indicated that the language you're using is C:
The concepts are the same but the function names are different.
 
Share this answer
 
v2
Comments
decodererror2345 24-Oct-12 7:31am    
i appreciate your answer but i want to do the program in c language. and i think upto some extent biginteger also fails if i take a really very large number..but thank u so much for ur comment.
C#
#include <stdio.h>
#include <math.h>

int main()
{
  long double c, n, fact = 1;
  printf("Enter a number to calculate it's factorial\n");
  scanf("%d", &n);
  for (c = 1; c <= n; c++)
  fact = fact * c;
  long double result=csqrtl(fact);
  printf("Squareroot of %d = %d\n", n, result);

  return 0;
}


----------------------------------------------------------------------------------------------------

for more details on square root refer to..
http://www.codecogs.com/reference/computing/c/math.h/sqrt.php[^]

I think this solves your problem.


for data type see my solution below
 
Share this answer
 
v3
Comments
CPallini 22-Oct-12 16:59pm    
Even a quadruple precision number cannot store 2000! result.
Perhaps the BigInteger structure can help you:(As C++ and C are almost same so try this: for data type to store.)

http://msdn.microsoft.com/en-us/library/system.numerics.biginteger.aspx
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900