پاسخ ها ( ۲ )

  1. class Program
    {
    static void Main(string[] args)
    {
    int a, b, c, num, i;
    a = 1; b = 1; c = 0;
    Console.Write(“n(st) digit: “);
    num = int.Parse(Console.ReadLine());

    for (i = 1; i <= num; i++)
    {
    c = a + b;
    Console.WriteLine("{0}st={1}", i, a);
    a = b;
    b = c;
    }

    Console.ReadKey();
    }
    }
    }

  2.  
    using System;
     
     
    namespace Fibonacci
    {
    class Program
    {
    try
    static void Main(string[] args)
    {
    {
    int n = Convert.ToInt32(Console.ReadLine());
     
    if (n < 1) { Console.WriteLine(“Input Number is less than 1”); }
    else
    Console.WriteLine(Fib(n));
    }
    catch (Exception exception)
    {
    Console.WriteLine(“Erorr:t”+exception.Message);
    }
     
     
     
    }
    public static int Fib(int n)
    {
    if (n <= 1)
    {
    return n;
    }
    else
    {
    return Fib(n – 1) + Fib(n – 2);
    }
     
     
     
     
     
     
    }
    }
    }

ارسال یک پاسخ