using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a = 0;
int b = 1;
int c = 0;
int i = 0;
Console.Write(a + ", " + b );
for (i = 1; i < 10; i++)
{
c = a + b;
Console.Write(", "+c);
a = b;
b = c;
}
Console.WriteLine();
}
}
}
Output
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55
In this program, we are taking two integer numbers 0 and 1 initially, program will add them and print third element as 1 (which is sum of 0 and 1) and then program will sum last two elements and print next element 2 (which is sum of 1 and 1) and so on… Here we are printing fibonacci series till 10 terms (10 elements).
Consider the program:
Output
In this program, we are taking two integer numbers 0 and 1 initially, program will add them and print third element as 1 (which is sum of 0 and 1) and then program will sum last two elements and print next element 2 (which is sum of 1 and 1) and so on… Here we are printing fibonacci series till 10 terms (10 elements).