Op Avanzadas- Naturales c#

public static string Porcentaje(double x, double y)
{
///Valida si los números se encuentran en el mismo rango
///si no es así retornará la excepción SystemException

if (x < 0 || y < 0)
{
throw new SystemException();
}else
{
double porcentaje = (x / 100) * y;
string res = porcentaje.ToString();
if (res.Contains(","))
{
int numEntero = int.Parse(res.Split(',')[0]);
double numDecimal = double.Parse("0," + res.Split(',')[1]);
string por = "\nParte entera: " + numEntero + "\nParte decimal: " + numDecimal;
return por;
}else
{
return res;
}
}
}
public static double Potencia(double x, double y)
{
if (x < 0 || y < 0)
{
throw new SystemException();
}else
{
double pot = Math.Pow(x, y);
return pot;
}
}


public static int Factorial(int x)
{
if (x < 0)
{
throw new SystemException();
}
else
{
int i, fact = 1;
if (x == 0)
{
return fact;
}
else
{
for (i = 1; i <= x; i++)
{
fact = fact * i;
}
return fact;
}
}
}

No hay comentarios:

Publicar un comentario