C# Static Class Tutorial
class testmath{
public static int sum(int a, int b)
{
return a + b;
}
public static Boolean prime(int a)
{
int b;
for (b = 2; b < a; b++)
{
if (a % b == 0)
break;
}
if (a == b)
return true;
else
return false;
}
public static int percentage(int a, int b)
{
return b / 100 * a;
}
}
class Program
{
static void Main(string[] args)
{
int a, b, c;
Console.Write("Enter Three Number>> ");
a = int.Parse(Console.ReadLine());
b = int.Parse(Console.ReadLine());
c = int.Parse(Console.ReadLine());
Console.WriteLine("\n{0} percentage of {1} is {2}" ,a,b,testmath.percentage(a,b));
if (testmath.prime(c) == true)
Console.WriteLine("\n{0} is Prime Number",c);
else
Console.WriteLine("{0} is Not Prime",c);
Console.Write("\nSum of {0}+{1} is {2}\n",a,b,testmath.sum(a,b));
}
}
No comments:
Post a Comment