Jump to content

C# Fibonacci nr Help

Redliquid
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 0;
            int b = 1;
            int sum = 1;
 
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(sum);
                sum = a + b;
                a += b;
                b += sum;
            }
            Console.ReadKey();
        }
    }
}
 
So i'm trying to get the fibonacci nrs up to 10 but for some reason my program skips every second number
Why

6e999bb7a4.png


 
My logic is in the white .txt file and the outcome from the program is in the black one to the right.

Redliquid~

Link to comment
Share on other sites

Link to post
Share on other sites

Nevermind i fixed it using my amazing brain Kappa

Redliquid~

Link to comment
Share on other sites

Link to post
Share on other sites

your logic for moving to the next number a+= b is incorrect.  should be a = b.  Same with sum.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×