One way to find the nth nonagonal number in C# is to use the formula (5 * n^2 - 3 * n) / 2
, where n
is the index of the nonagonal number starting from zero.
Here's an implementation of this formula in C#:
main.cs87 chars5 lines
You can then call this method with the desired index n
to get the corresponding nonagonal number. For example, to find the 5th nonagonal number, you can do:
main.cs53 chars2 lines
This will give you the result of 70
, which is the 5th nonagonal number.
gistlibby LogSnag