frequently asking logical program in interviews for dotnet fresher
Fibonacci series program in c# using for loop
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication84
{
class Program
{
static void Main(string[] args)
{
int i, n, f1 = 0, f2 = 1, f3 = 0; /*variables declaration*/
Console.WriteLine("enter a no:");
n = int.Parse(Console.ReadLine());
Console.WriteLine(f1);
Console.WriteLine(f2);
for (i = 0; i <= n; i++) /*loop implementation*/
{
/*logic for loop*/
f3 = f1 + f2;
Console.WriteLine(f3); /*print output*/
f1 = f2;
f2 = f3;
}
Console.ReadLine();
}
}
}
Fibonacci series program in c# using for loop
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication84
{
class Program
{
static void Main(string[] args)
{
int i, n, f1 = 0, f2 = 1, f3 = 0; /*variables declaration*/
Console.WriteLine("enter a no:");
n = int.Parse(Console.ReadLine());
Console.WriteLine(f1);
Console.WriteLine(f2);
for (i = 0; i <= n; i++) /*loop implementation*/
{
/*logic for loop*/
f3 = f1 + f2;
Console.WriteLine(f3); /*print output*/
f1 = f2;
f2 = f3;
}
Console.ReadLine();
}
}
}
output: Screen Shot
No comments:
Post a Comment