Tuesday, June 19, 2012

fibonacci series in c#


using System;

namespace fibonic
{
    class Program
    {
        static void Main(string[] args)
        {
            int a=0, b=1,n, c, i;
            Console.WriteLine("Enter no for fibonic series");
            n = int.Parse(Console.ReadLine());
            Console.WriteLine("Fibonic series is:");
            Console.WriteLine(""+a);
            Console.WriteLine("" +b);
         
            for (i = 1; i <= n; i++)
            {
                c= a + b;
                a= b;
                b = c;
                Console.WriteLine("" + c);
           

            }
            Console.ReadKey();
         
        }
    }
}

Output
Enter no for fibonic series
6
Fibonic series is:
0
1
1
2
3
5
8
13

12 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. goo done ..can u plz upload the code for palindrome ..

    ReplyDelete
    Replies
    1. #include
      using namespace std;
      int main(){
      int n,num=0,rev=0,rem=0,sum=0;
      cout<<"enter value of n"<>n;
      num=n;
      while(n>0){
      rem=n%10;
      rev=rev*10+rem;
      n=n/10;
      }
      if(num==rev){
      cout<<"pailendrone"<<endl;
      }
      else{
      cout<<"not pailendrone"<<endl;
      }
      return 0;
      }

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. int a = 1, b = 0, c = 0;
    for (int i = 1; i < 10;i++ )
    {
    Console.Write("{0} ", a);
    b = c;
    c = a;
    a = b + c;


    }

    Console.ReadKey();
    its a perfect example

    ReplyDelete
  5. THANKS DEAR FOR THIS PROGRAM & THIS IS VERY NICE ARTICLE

    ReplyDelete
  6. Well done friend........ Simple and easy..

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Can you please write the program for the unmatching data from the two arrays. Like if A={1,3,7,9} B={2,3,5,7} then i want the output like O/P: 2,5 (i.e Unmatched data from the second array) Plz reply me soon.

    ReplyDelete