Step 1:- Method
public void PrintFibonacci()
{
int num1
= 1;
int num2
= 1;
int Num3;
Console.WriteLine("Enter
number");
Num3
= Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Fibonacci
number");
while (num2
< Num3)
{
Console.WriteLine(num1);
num2
= num2 + num1;
num1
= num2 - num1;
};
}
Method 2:- Complete code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Console_Application_Demo
{
class Program
{
public void PrintFibonacci()
{
int num1
= 1;
int num2
= 1;
int Num3;
Console.WriteLine("Enter
number");
Num3
= Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Fibonacci
number");
while (num2
< Num3)
{
Console.WriteLine(num1);
num2
= num2 + num1;
num1
= num2 - num1;
};
}
static void Main(string[]
args)
{
Program p
= new Program();
p.PrintFibonacci();
Console.ReadLine();
}
}
}
Example:-
No comments:
Post a Comment