# C sharp dot net example programs for beginers?

## C#.net Programs

Program # 1:This program takes three positive numbers from user. Compute and display the average of the two larger numbers.

using System;

using System.Collections.Generic;

using System.Text;

namespace Average_of_three_Nos

{

class Program

{

static void Main(string[] args)

{

string no1, no2, no3;

int n1, n2, n3;

int average;

Console.WriteLine("Enter First Number");

n1 = Int32.Parse(no1);

Console.WriteLine("Enter Second Number");

n2 = Int32.Parse(no2);

Console.WriteLine("Enter third Number");

n3 = Int32.Parse(no3);

average = (n1 + n2 + n3) / 3;

Console.WriteLine("Average of three Numbers : "+ average);

}

}

}

Program #2:This program will take two positive numbers as its input and then find GCD of them.

using System;

using System.Collections.Generic;

using System.Text;

namespace GCD

{

class Program

{

static void Main(string[] args)

{

Program obj = new Program();

string no1, no2;

int n1, n2;

Console.WriteLine("Enter First Number");

n1 = Int32.Parse(no1);

Console.WriteLine("Enter Second Number");

n2 = Int32.Parse(no2);

int g=obj.find_gcd(n1, n2);

Console.WriteLine("GCD=" + g);

}

int find_gcd(int a, int b)

{

int c;

if(a<b)

{

c = a;

a = b;

b = c;

}

while(true)

{

c = a%b;

if(c==0)

return b;

a = b;

b = c;

}

}

}

}