Csharp/CSharp Tutorial/Data Type/long Calculation
Версия от 15:31, 26 мая 2010; (обсуждение)
Содержание
Calculate with ulong
using System;
class MainClass
{
static void Main(string[] args)
{
ulong loopCount = 0;
ulong factorial = 1;
loopCount = 23;
for( ulong i = loopCount; i > 0; i-- )
{
factorial *= i;
}
Console.WriteLine( "{0}! = {1}", loopCount, factorial );
}
}Dividing a Float by Zero, Displaying NaN
class MainClass
{
static void Main()
{
float n=0f;
System.Console.WriteLine(n / 0);
}
}Overflowing the Bounds of a float
class MainClass
{
static void Main()
{
System.Console.WriteLine(-1f / 0);
System.Console.WriteLine(3.402823E+38f * 2f);
}
}Use long to compute the distance from the Earth to the sun in inches
using System;
class MainClass {
public static void Main() {
long inches;
long miles;
miles = 93000000; // 93,000,000 miles to the sun
// 5,280 feet in a mile, 12 inches in a foot
inches = miles * 5280 * 12;
Console.WriteLine("Distance to the sun: " + inches + " inches.");
}
}Distance to the sun: 5892480000000 inches.