Monday, December 17, 2012

PROGRAM TO GENERATE FIBONACCI SERIES

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication8
{
class Fabonacci
{
static void Main(string[] args)
{
int num, a, b, c, i;
Console.Write("Enter the Number of TERMS in the series: ");
String strNUM = Console.ReadLine();
num = int.Parse(strNUM);
a = 0;
b = 1;
Console.Write(""+a+" "+b);
for (i = 3; i <= num; i++)
{
c = a + b;
a = b;
b = c;
Console.Write(" "+c);
}
Console.ReadLine();
}
}
}

<<<<<<<<<<<<<<<<<<< OUTPUT >>>>>>>>>>>>>>>>>>>>>>>>>>>>

Enter the Number of TERMS in the series: 5

0 1 1 2 3

No comments:

Post a Comment