Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8285643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:31:20+00:00 2026-06-08T11:31:20+00:00

This small program tests the two approaches of computing the factorial – by iteration

  • 0

This small program tests the two approaches of computing the factorial – by iteration and by recursion.

Factorial.cs:

using System;

namespace Functions
{
    public class Factorial
    {
        public static ulong CalcRecursively(int number)
        {
            if (number > 1)
                return (ulong)number * CalcRecursively(number - 1);
            if (number <= 1)
                return 1;

            return 0;
        }

        public static ulong Calc(int number)
        {
            ulong rValue=1;

            for (int i = 0; i < number; i++)
            {
                rValue = rValue * (ulong)(number - i);                
            }

            return rValue;

        }


    }
}

MainProgram.cs:

using System;

using Functions;
class FunctionClient
{


    public static void Main()
    {

        Console.WriteLine("{0}\n", Functions.Factorial.CalcRecursively(TESTED_VALUE));
        Console.WriteLine("{0}\n", Functions.Factorial.Calc(TESTED_VALUE));

        Console.ReadKey();

    }

    const int TESTED_VALUE = 60;

}

Console:

9727775195120271360
9727775195120271360

It’s ok with low figures, but otherwise(f.ex. with 60) it outputs the incorrect values, according to the most reliable source on the internet. Could you point out my mistake? It’s unbeliveable for me that the two totally different methods works wrong in exactly the same manner.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:31:21+00:00Added an answer on June 8, 2026 at 11:31 am

    You are running into the limits of C#’s ulong data type. It is a 64-bit data structure which limits it to a maximum value of 18,446,744,073,709,551,615 according to MSDN.

    If you do want to explore larger numbers, .NET 4 introduced the BigInteger structure you may be interested in.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is a small program using Java Scanner which reads a file of double
Here's a small test program I wrote: #include <iostream> using namespace std; class A
I'm writing a small C++ program that tests C dlls, containing some functions. Those
I'm running this small C# test program launched from a pre-commit batch file private
Consider this small program: #include <stdio.h> #include <stdlib.h> // Change 60000 to 70000 and
How can I include foo() function of foo.c in this small program (sorry for
I wrote this small C++ program and built it(Release) #include<iostream> int main(){ std::cout<<Hello World;
I made my own small thread-safe (confirmed it using many tests)library similar to Looper
I have made a small webserver as a mock for my JUnit tests. this
I have this small class looking like this: private static int field1 = -

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.