Understanding C# Method for Calculating Factorials

  • Context: C# 
  • Thread starter Thread starter Chestermiller
  • Start date Start date
  • Tags Tags
    Method
Click For Summary
SUMMARY

The discussion centers on the C# method for calculating factorials using recursion, specifically the implementation of the method long factorial(int dataValue). The method demonstrates a recursive call where the function calls itself with a decremented value until it reaches the base case of dataValue == 0, which should return 1. Participants highlight the elegance of recursion compared to iterative methods but note that recursion can be more resource-intensive. The importance of handling the base case correctly to avoid infinite recursion is emphasized.

PREREQUISITES
  • Understanding of C# programming language
  • Familiarity with recursive algorithms
  • Knowledge of stack memory management
  • Basic concepts of function calls and return values
NEXT STEPS
  • Learn about C# recursion and its performance implications
  • Explore iterative versus recursive approaches for factorial calculation
  • Study stack memory usage in recursive function calls
  • Investigate error handling in recursive algorithms
USEFUL FOR

Software developers, particularly those working with C# and interested in algorithm design, as well as educators teaching recursion concepts in programming.

  • #61
So, monadic constructs are things I really didn't get when I was looking at Haskell. The "types" of problems I was playing with at the time were computer algebra type things, vector spaces, groups and such. Just trying to learn. I came away feeling okay, cool, what do I get from this effort?
 
  • Like
Likes   Reactions: sysprog
Technology news on Phys.org
  • #62
Paul Colby said:
So, monadic constructs are things I really didn't get when I was looking at Haskell. The "types" of problems I was playing with at the time were computer algebra type things, vector spaces, groups and such. Just trying to learn. I came away feeling okay, cool, what do I get from this effort?
I would just use MATLAB (or Mathematica/Wolfram) for most of that. For one-offs, my TI-83 is usually more than adequate for my purposes. If I need to do, e.g., a computationally intensive set of Fourier transforms, I'll use routines out of the Fortran library.

Most of my programming work is in IBM mainframe OS interfacing, and most of that is done in assembly language. Some of it is fixing other people's code, in whichever language they wrote it in.

On the PC, I prefer to use assembly language over using high-level languages, but I'll work with whatever best gets the job done. Subject to the condition that I prefer to code in languages I already know, in general, if I have a choice, I try to use whichever language I think is best for the problem I'm dealing with.
 
Last edited:
  • #63
I just reinstalled Haskell, I'm holding you directly responsible.
 
  • Haha
Likes   Reactions: sysprog
  • #64
The plus side of using functional languages (real functional languages, without side-effects, not languages that just look functional) is referential transparency. If you convince yourself that an expression always evaluates to some particular value, you can replace it by that value, and your program will work the same way. That's a powerful way to reason about programs.
 
  • Like
Likes   Reactions: Nugatory and sysprog
  • #65
For @Chestermiller or anybody else, there's a nice book by RB Whittaker I forgot its name on C# so far looks like a great book, and also a website with solutions to the problems in it.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 19 ·
Replies
19
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 22 ·
Replies
22
Views
3K
  • · Replies 17 ·
Replies
17
Views
3K
Replies
4
Views
3K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
Replies
22
Views
5K