0% found this document useful (0 votes)
147 views7 pages

Sanfoundry Sourcecode

The document contains code snippets from multiple C# programs: 1) A program to calculate acceleration from velocity and time by dividing velocity by time. 2) A program to find the third side of a right triangle using the Pythagorean theorem. 3) A program to perform division of exponents with the same base by subtracting the exponents. 4) A program implementing a for-each loop in an interface to iterate through a dynamically resizing array. 5) A program implementing a phone book using a hashtable to lookup phone numbers by name from a text file.

Uploaded by

chessgeneral
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views7 pages

Sanfoundry Sourcecode

The document contains code snippets from multiple C# programs: 1) A program to calculate acceleration from velocity and time by dividing velocity by time. 2) A program to find the third side of a right triangle using the Pythagorean theorem. 3) A program to perform division of exponents with the same base by subtracting the exponents. 4) A program implementing a for-each loop in an interface to iterate through a dynamically resizing array. 5) A program implementing a phone book using a hashtable to lookup phone numbers by name from a text file.

Uploaded by

chessgeneral
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

/*

* C# Program to Calculate Acceleration

using System;

class program

static void Main(string[] args)

int v, t, acc;

[Link]("Enter the Velocity : ");

v = [Link]([Link]());

[Link]("Enter the Time : ");

t = [Link]([Link]());

acc = v / t;

[Link]("Acceleration : {0}", acc);

}
-----------------------------------------------------------------------------
--
/*

* C# Program to Find a Number using Pythagoras Theorem

*/

using System;

using [Link];

using [Link];

using [Link];

class Program

static void Main(string[] args)

double a, b, c;

[Link]("Enter the First Value ");


a = [Link]([Link]());

[Link]("Enter the Second Value ");

b = [Link]([Link]());

c = [Link](a * a + b * b);

[Link]("The Other Number is : {0}", c);

[Link]();

}
-----------------------------------------------------------------------------
--
/*

* C# Program to Perform Division of Exponents of Same Base

*/

using System;

class Program

static void Main()

[Link]("Enter the Base : ");

double num = [Link]([Link]());

[Link]("Enter the First Exponent :");

double exp1 = [Link]([Link]());

[Link]("Enter the Second Exponent :");

double exp2 = [Link]([Link]());

double div;

div = exp1 - exp2;

[Link]("Result is : {0}^{1} : {2}", num, div, [Link](num,


div));

[Link]();

}
-----------------------------------------------------------------------------
--
/*

* C# Program to Implement for-each in Inteface

*/

using System;

using [Link];

class GrowableArray : IEnumerable

object[] a;

public GrowableArray(int size)

a = new object[size];

public GrowableArray() : this(8) {}

void Grow()

object[] b = new object[2 * [Link]];

[Link](a, b, [Link]);

a = b;

public object this[int i]

set

if (i >= [Link]) Grow();

a[i] = value;

get

if (i >= [Link]) 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 < [Link] && a[i] == null);

if (i == [Link])

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) [Link](" " + x);

}
-----------------------------------------------------------------------------
--
/*

* C# Program to Implement PhoneBook

*/

using System;

using [Link];

using [Link];

class PhoneBook

static void Main(string[] arg)

Hashtable tab = new Hashtable();

string fileName;

if
{

([Link] > 0) fileName = arg[0];

else

fileName = "[Link]";

StreamReader r = [Link](fileName);

string line = [Link]();

while (line != null)

int pos = [Link]('=');

string name = [Link](0, pos).Trim();

long phone = Convert.ToInt64([Link](pos + 1));

tab[name] = phone;

line = [Link]();

[Link]();

for (; ; )

[Link]("Name : ");

string name = [Link]().Trim();

if (name == "")

break;

object phone = tab[name];

if (phone == null)

[Link]("-- Not Found in Phone Book");

else

[Link](phone);

}
}

}
-----------------------------------------------------------------------------
--

You might also like