?

Log in

Previous Entry | Next Entry

These are some strangec# interview questions which are asked in big companies to test your logical thinking ability. Before we move ahead lets first to understand what exactly is Fibonacci series. Fibonacci series are nothing but series of numbers 0,1,1,2,3,5 and so on.

The specialty of this series is that next number is addition of previous two numbers. Below figure explains how Fibonacci series works. We first start with 0 and 1. The next number is addition of “0 + 1” which will give us “1”. The next number will be again addition of previous value which is “1” and the current value which is “1” which will give us “2” and so on.

                                  123 im

Implementing Fibonacci series in c# is a 4 step process. Below image shows the same in a pictorial format.

                                          123 im 2

Step 1:- Define 3 variables “Prev”,”Next” and “Sum”. Initialize these variable with “Prev=1” , “Next = -1” and “Sum=0”.


Step 2:- Add “Prev” and “Next” variable to get the Sum. Display the “Sum” variable.


Step 3:- Swap “Prev” value to “Next” and “Sum” to “Previous”.


Step 4:- Execute “Step 2” and “Step 3” again for the next Fibonacci value.


Below is how the code will look like. Do follow the steps in comment.

123 im 3

The above question is taken from the bestselling c# and .NET interview question book written by Shivprasadkoirala and published by BPB publication.

References

Copy right www.questpond.com

Buy 600+ Real Time Interview Videos

Call +91-22-66752917 or mail us on questpond@questpond.com for more details on C#, .NET, ASP.NET, SQL Server interview question videos.

SQL Server interview question videos

Latest Month

January 2017
S M T W T F S
1234567
891011121314
15161718192021
22232425262728
293031    

Tags

Powered by LiveJournal.com