11,570 questions
Take a look at this:
using System;
namespace ConsoleApp1
{
class Program
{
static void main(string[] args)
{
int i, n;
// initialize first and second terms
int t1 = 0, t2 = 1;
// initialize the next term (3rd term)
int nextTerm = t1 + t2;
// get no. of terms from user
Console.WriteLine("Enter the number of terms: ");
n = Convert.ToInt32(Console.ReadLine());
// print the first two terms t1 and t2
Console.Write($"Fibonacci Series: {t1}, {t2}, ");
// print 3rd to nth terms
for (i = 3; i <= n; ++i)
{
Console.Write($"{nextTerm}, ");
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
}
}
}
}