- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a C# function to print nth number in Fibonacci series?
Set the following, if the nth number is let’s say num −
int n = num- 1; int[] val = new int[n + 1];
Then set the default Fibonacci numbers on the first and second position −
val[0]= 0; val[1]= 1;
Loop through i=2 to i<=n and find the Fibonacci numbers −
for (int i = 2; i <= n;i++) { val[i] = val[i - 2] + val[i - 1]; }
The following is the complete code −
Example
using System; public class Demo { public static void Main(string[] args) { Demo g = new Demo(); int a = g.displayFibonacci(7); Console.WriteLine(a); } public int displayFibonacci(int num) { int n = num- 1; int[] val = new int[n + 1]; val[0]= 0; val[1]= 1; for (int i = 2; i <= n;i++) { val[i] = val[i - 2] + val[i - 1]; } return val[n]; } }
Output
8
- Related Articles
- Write a Golang program to print the Fibonacci series
- Python Program for nth multiple of a number in Fibonacci Series
- Java Program for nth multiple of a number in Fibonacci Series
- Java program to print Fibonacci series of a given number.
- Java program to print a Fibonacci series
- Program to find Nth Even Fibonacci Number in C++
- C++ program to find Nth Non Fibonacci Number
- How to get the nth value of a Fibonacci series using recursion in C#?
- Nth element of the Fibonacci series JavaScript
- Program to find Nth Fibonacci Number in Python
- Java program to print the fibonacci series of a given number using while loop
- C program to find Fibonacci series for a given number
- Program to find Fibonacci series results up to nth term in Python
- Program to find last two digits of Nth Fibonacci number in C++
- Validate a number as Fibonacci series number in JavaScript

Advertisements