**Prime number logic.**

using System;

using System.Collections.Generic;

using System.Text;

namespace Primenumbers

{

class Program

{

static void Main(string[] args)

{

//define limit

int limit = 100;

Console.WriteLine(“Prime numbers between 1 and ” + limit);

//loop through the numbers one by one

for(int i=1; i < 100; i++)

{

bool isPrime = true;

//check to see if the number is prime

for(int j=2; j < i ; j++)

{

if(i % j == 0){

isPrime = false;

break;

}

}

// print the number

if(isPrime)

Console.Write(i + ” “);

}

}

}

}

**Fibonacci Series Example**

/*

Fibonacci Series Example

This Fibonacci Series Example shows how to create and print

Fibonacci Series using .

*/

using System;

using System.Collections.Generic;

using System.Text;

namespace Primenumbers

{

class Program

{

static void Main(string[] args)

{

//number of elements to generate in a series

int limit = 20;

long[] series = new long[limit];

//create first 2 series elements

series[0] = 0;

series[1] = 1;

//create the Fibonacci series and store it in an array

for(int i=2; i < limit; i++){

series[i] = series[i-1] + series[i-2];

}

//print the Fibonacci series numbers

Console.WriteLine(“Fibonacci Series upto ” + limit);

for(int i=0; i< limit; i++){

Console.Write(series[i] + ” “);

}

}

}

}

/*

Output of the Fibonacci Series Example would be

Fibonacci Series upto 20

0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181

*/

**Read Number from Console and Check if it is a Palindrome Number**

/*

Read Number from Console and Check if it is a Palindrome Number

This example shows how to input the number from console and

check if the number is a palindrome number or not.

*/

using System;

using System.Collections.Generic;

using System.Text;

namespace Primenumbers

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine(“Enter the number to check..”);

double number = 0;

try

{

//take input from console

string br =Console.ReadLine();

//parse the line into int

number = Convert.ToDouble(br);

}

catch(FormatException ne)

{

Console.WriteLine(“Invalid input: ” + ne.Message);

}

Console.WriteLine(“Number is ” + number);

double n = number;

double reversedNumber = 0;

double temp=0;

//reverse the number

while(n > 0){

temp = n % 10;

n = n / 10;

reversedNumber = reversedNumber * 10 + temp;

}

/*

* if the number and it’s reversed number are same, the number is a

* palindrome number

*/

if(number == reversedNumber)

Console.WriteLine(number + ” is a palindrome number”);

else

Console.WriteLine(number + ” is not a palindrome number”);

}

}

}

/*

Output of the program would be

Enter the number to check..

121

Number is 121

121 is a palindrome number

*/

**Largest and Smallest Number in an Array Example**

/*

Find Largest and Smallest Number in an Array Example

This Example shows how to find largest and smallest number in an

array.

*/

using System;

using System.Collections.Generic;

using System.Text;

namespace LogicalSamples

{

class Program

{

static void Main(string[] args)

{

//array of 10 numbers

int[] numbers = new int[]{32,43,53,54,32,65,63,98,43,23};

//assign first element of an array to largest and smallest

int smallest = numbers[0];

int largetst = numbers[0];

for(int i=1; i< numbers.Length; i++) { if(numbers[i] > largetst)

largetst = numbers[i];

else if (numbers[i] < smallest)

smallest = numbers[i];

}

Console.WriteLine(“Largest Number is : ” + largetst);

Console.WriteLine(“Smallest Number is : ” + smallest);

}

}

}

/*

Output of this program would be

Largest Number is : 98

Smallest Number is : 23

*/

**Reverse Number**

/*

This Reverse Number Example shows how to reverse a given number.

*/

using System;

using System.Collections.Generic;

using System.Text;

namespace LogicalSamples

{

class Program

{

static void Main(string[] args)

{

//original number

int number = 1234;

int reversedNumber = 0;

int temp = 0;

while(number > 0){

//use modulus operator to strip off the last digit

temp = number%10;

//create the reversed number

reversedNumber = reversedNumber * 10 + temp;

number = number/10;

}

//output the reversed number

Console.WriteLine(“Reversed Number is: ” + reversedNumber);

}

}

}

/*

Output of this Number Reverse program would be

Reversed Number is: 4321

*/