a=a+b;
b=a-b;
a=a-b;
Thursday, 20 December 2012
fibonacci series in c sharp
using System; class Program { public static int Fibonacci(int n) { int a = 0; int b = 1; // In N steps compute Fibonacci sequence iteratively. for (int i = 0; i < n; i++) { int temp = a; a = b; b = temp + b; } return a; } static void Main() { for (int i = 0; i < 15; i++) { Console.WriteLine(Fibonacci(i)); } } }
Prime Numbers between ’0′ and ’100′ in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PrimeNumber
{
class Program
{
static void Main(string[] args)
{
bool isPrime = true;
for (int i = 1; i <= 100; i++)
{
for (int j = 2; j <= 100; j++)
{
if (i != j && i % j == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
{
Console.WriteLine("Prime:" + i);
}
isPrime = true;
}
Console.ReadKey();
}
}
}
Subscribe to:
Posts (Atom)