C# Understanding C# Method for Calculating Factorials

  • Thread starter Thread starter Chestermiller
  • Start date Start date
  • Tags Tags
    Method
Click For Summary
C# methods can indeed call themselves, a concept known as recursion, which is used effectively in calculating factorials. The provided factorial method demonstrates this by multiplying the input value by the factorial of the input value minus one until it reaches the base case. It's essential to handle the case for 0! = 1 to prevent overflow and infinite recursion. While recursive functions can be elegant, they may be less efficient than iterative solutions like for loops. Understanding the logical flow of recursive calls is crucial for mastering this programming technique.
  • #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 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 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 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 4 ·
Replies
4
Views
1K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 23 ·
Replies
23
Views
3K