Here we will write a simple program to print Fibonacci Series. In the Fibonacci Series, the next number is the sum of the previous two numbers.
C# Program to Print Fibonacci Series
In the Fibonacci Series, the next number is the sum of the previous two numbers.
0, 1, 1, 2, 3, 5, 8, 13, 21 etc
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main(string[] args) { int iFirst = 0, iSecond = 1, iThird, iCount, iInput; Console.Write("Enter the number of elements: "); iInput = int.Parse(Console.ReadLine()); Console.Write(iFirst + " " + iSecond + " "); //printing 0 and 1 for (iCount = 2; iCount < iInput; ++iCount) //loop starts from 2 because 0 and 1 are already printed { iThird = iFirst + iSecond; Console.Write(iThird + " "); iFirst = iSecond; iSecond = iThird; } Console.ReadKey(); } }
Output:
Enter the number of elements: 6 >0 1 1 2 3 5
View More:
- C# Program to check whether a number is prime or not using Recursion.
- C# Program to find the sum of all item of an Integer Array.
- C# Program to find Largest Element in a Matrix.
- C# Program to Swap two numbers without using third variable.
Conclusion:
I hope you would love this post. Please don’t hesitate to comment for any technical help. Your feedback and suggestions are welcome.
indian pharmacy best online pharmacy pharmacy near me
canadian pharmacy reviews erectile dysfunction pills pharmacies near me
cheap viagra online canadian pharmacy pharmacy near me canadian mail order pharmacy
people’s pharmacy rx e d
best drugstore bb cream specialty pharmacy dysfunction
ed medication discount pharmacy erectile
canada drugs http://pharmacy-onlineasxs.com/ peoples pharmacy
Hello! This is my 1st comment here so I just wanted to give a quick shout out and say I really enjoy reading your posts. Can you recommend any other blogs/websites/forums that cover the same subjects? Thanks a lot!
Its like you read my mind! You appear to know a lot about this, like you wrote the book in it or something. I think that you could do with a few pics to drive the message home a bit, but instead of that, this is excellent blog. A fantastic read. I’ll certainly be back.
I was wondering if you ever thought of changing the page layout of your blog? Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect with it better. Youve got an awful lot of text for only having one or two images. Maybe you could space it out better?|
With almost everything which appears to be building throughout this area, your points of view are actually very exciting. Having said that, I appologize, but I can not give credence to your whole idea, all be it exciting none the less. It appears to me that your comments are not completely justified and in reality you are your self not really wholly confident of the argument. In any event I did appreciate looking at it.