Program 1:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace Fibonacci

{

    class Program

    {

        static void Main(string[] args)

        {

            int say, tpl = 0, a = 0, b = 1, c=0, sec;

            Console.Write("Bir sayı giriniz : ");

            sec = Convert.ToInt32(Console.ReadLine());

            Console.Write("Seri : "+a);

            for (say = 1; say < sec ; say++)

 

            {  

                c = a + b;

                a = b;

                b = c;

                tpl += a;

                Console.Write("--"+a);

            }

            Console.WriteLine();

            Console.WriteLine(sec+" sayısına kadar olan serinin toplamı: "+tpl);

            Console.ReadLine();

        }

    }

}

 

yukarıdaki programda sayılar gösterilmiş ve toplamı hesaplanmıştır.

Farklı bir çözüm yolu da aşağıda verilmiştir.

 

Program 2:

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ConsoleApplication20

{

    class Program

    {

        static void Main(string[] args)

        {

            int say, tpl = 1, a = 0, b = 1, sec;

            sec = Convert.ToInt32(Console.ReadLine());

            for (say = 1; say < sec - 1; say++)

            {

                switch (say % 2)

                {

                    case 1:

 

                        a += b;

                        tpl += a;

                        break;

                    case 0:

 

                        b += a;

                        tpl += b;

                        break;

                }

            }

            Console.WriteLine(tpl);

            Console.ReadLine();

        }

    }

}

bu programda ise sadece toplam yazılmıştır.

Yorum ekle


Submit to FacebookSubmit to Google PlusSubmit to Twitter
01242977
Bugün
Ay
Toplam
79
4736
1242977

Your IP: 18.216.190.167
2024-04-16 04:02