Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 13:36

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Coding Problem

Discussion on Coding Problem within the .NET Languages forum part of the Coders Den category.

Reply
 
Old   #1
 
x[t]c's Avatar
 
elite*gold: 0
Join Date: Mar 2009
Posts: 33
Received Thanks: 6
Coding Problem

I am working on a project and needing to solve this without using a loop. Any math genius in here able to do this without using a loop?

PHP Code:

while (>= 1)
{
     
* (1);
     
x--;

x[t]c is offline  
Old 06/03/2022, 12:35   #2


 
Jeoni's Avatar
 
elite*gold: 966
Join Date: Apr 2010
Posts: 1,105
Received Thanks: 681
1.
Sure. Let's assume you start with
Code:
x = n
y = c
2.
So after the loop ran you have
Code:
x = 0
y = c * (n + 1) * ((n - 1) + 1) * ((n - 2) + 1) * ... * (2 + 1) * (1 + 1)
3.
Let's simplify y, so we can see what is going on.
Code:
y = c * (n + 1) * n * (n - 1) * ... * 3 * 2
y = c * (2 * 3 * ... * n * (n + 1))
y = c * (n+1)!
So it is the factorial.

4.
Now you can replace the code you have there with something like that:
Code:
y = y * factorial(x + 1)
x = 0
5.
The problem is, that the factorial needs a loop / recursion which is to be avoided.
So you may use Stirling's approximation to calculate the factorial without having a loop / recursion.

With best regards

/Edit: On a second thought, you're probably a student in some starting semester and the task is to reformulate that into a recursive function (which performs usually worse than the corresponding iterative approach using a loop). In that case the solution is something like that:
Code:
NumberType GarbageRecursiveFactorial(NumberType x)
{
    if (x > 1)
        return x * GarbageRecursiveFactorial(x - 1);
    else
        return 1;
}

y = y * GarbageRecursiveFactorial(x + 1);
x = 0
Jeoni is offline  
Reply


Similar Threads Similar Threads
*NEW CODING ART!!!..........:::::~WhiteLight D3D~:::::..........*NEW CODING ART!!!
09/21/2010 - WarRock Hacks, Bots, Cheats & Exploits - 25 Replies
http://250kb.de/u/100911/p/m4buevNCZhoQ.PNG Download: Multiupload.com - upload your files to multiple file hosting sites! VirusScan: VirusTotal - Free Online Virus, Malware and URL Scanner Funktionen: SuperJump Teleport NoSpread NoRecoil
Uce Coding+ winhex coding
03/05/2009 - Dekaron - 8 Replies
i was just wondering is it true if u do coding with winhex is it less dc?? tats all cuz uce coding dcs me alot



All times are GMT +1. The time now is 13:37.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.