/*
* C# Program to Calculate Acceleration
using System;
class program
static void Main(string[] args)
int v, t, acc;
Console.WriteLine("Enter the Velocity : ");
v = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Time : ");
t = int.Parse(Console.ReadLine());
acc = v / t;
Console.WriteLine("Acceleration : {0}", acc);
}
-----------------------------------------------------------------------------
--
/*
* C# Program to Find a Number using Pythagoras Theorem
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
static void Main(string[] args)
double a, b, c;
Console.WriteLine("Enter the First Value ");
a = double.Parse(Console.ReadLine());
Console.WriteLine("Enter the Second Value ");
b = double.Parse(Console.ReadLine());
c = Math.Sqrt(a * a + b * b);
Console.WriteLine("The Other Number is : {0}", c);
Console.ReadLine();
}
-----------------------------------------------------------------------------
--
/*
* C# Program to Perform Division of Exponents of Same Base
*/
using System;
class Program
static void Main()
Console.WriteLine("Enter the Base : ");
double num = double.Parse(Console.ReadLine());
Console.WriteLine("Enter the First Exponent :");
double exp1 = double.Parse(Console.ReadLine());
Console.WriteLine("Enter the Second Exponent :");
double exp2 = double.Parse(Console.ReadLine());
double div;
div = exp1 - exp2;
Console.WriteLine("Result is : {0}^{1} : {2}", num, div, Math.Pow(num,
div));
Console.ReadLine();
}
-----------------------------------------------------------------------------
--
/*
* C# Program to Implement for-each in Inteface
*/
using System;
using System.Collections;
class GrowableArray : IEnumerable
object[] a;
public GrowableArray(int size)
a = new object[size];
public GrowableArray() : this(8) {}
void Grow()
object[] b = new object[2 * a.Length];
Array.Copy(a, b, a.Length);
a = b;
public object this[int i]
set
if (i >= a.Length) Grow();
a[i] = value;
get
if (i >= a.Length) Grow();
return a[i];
public IEnumerator GetEnumerator()
return new GAEnumerator(a);
class GAEnumerator : IEnumerator
object[] a;
int i = -1;
public GAEnumerator(object[] a) { this.a = a; }
public object Current
get
return a[i];
public void Reset()
i = -1;
public bool MoveNext()
do i++;
while (i < a.Length && a[i] == null);
if (i == a.Length)
return false;
else return true;
class Test
public static void Main()
GrowableArray a = new GrowableArray(2);
a[0] = 0;
a[1] = 1;
a[3] = 3;
foreach (object x in a) Console.Write(" " + x);
}
-----------------------------------------------------------------------------
--
/*
* C# Program to Implement PhoneBook
*/
using System;
using System.Collections;
using System.IO;
class PhoneBook
static void Main(string[] arg)
Hashtable tab = new Hashtable();
string fileName;
if
{
(arg.Length > 0) fileName = arg[0];
else
fileName = "phoneBook.txt";
StreamReader r = File.OpenText(fileName);
string line = r.ReadLine();
while (line != null)
int pos = line.IndexOf('=');
string name = line.Substring(0, pos).Trim();
long phone = Convert.ToInt64(line.Substring(pos + 1));
tab[name] = phone;
line = r.ReadLine();
r.Close();
for (; ; )
Console.Write("Name : ");
string name = Console.ReadLine().Trim();
if (name == "")
break;
object phone = tab[name];
if (phone == null)
Console.WriteLine("-- Not Found in Phone Book");
else
Console.WriteLine(phone);
}
}
}
-----------------------------------------------------------------------------
--