By Think Positive, Get Positive on 3:11:00 PM
Filed Under: Integers, program using byte and for loop, program using Long, types of integers
Integers:
- C# defines nine integer types and they are char, byte, sbyte, short, ushort, int, uint, long and ulong.
- The bit width and ranges of integers are shown below
- byte ------------------------- 8 -------------------------0 to 255
- sbyte------------------------- 8 -------------------- -128 to 127
- short -------------------------16---------------- -32768 to 32767
- ushort----------------------- 16--------------------------- 0 to 65535
- int ----------------------------32---------- -2147483648 to 2147483647
- uint --------------------------32 --------------------------- 0 to 4294965295
- long-------------------------- 64-------- −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
- ulong ------------------------64 -----------------------------0 to 18,446,744,073,709,551,615
using system;
class inch
{
public static void Main()
{
long mile;
long inch;
mile = 93000000;
inch = mile*5280*12;
Console.WriteLine("The distance to the Sun:"+inch+"inches");
}
}
Output:
The distance to the Sun: 5892480000000 inches
Program using byte to control the for loop that produces the summation of the number 100
using system;
class using_byte
{
public static void Main()
{
byte x;
int y;
y=0;
for(x=1;x<+100;x++)
y=y+x;
Console.WriteLine("The sum of 100 is "+y);
}
}
output:
The sum of 100 is 5050
goto Double
0 comments for this post