Lately I've been hating myself for choosing software as a main subject, this is why:
// Write a program which finds the factorial of a number
Console.Write("Enter a Number: ");
int factNum = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
for (int i = 1; i <= factNum; i++)
{
if (factNum % i == 0)
{
System.Console.Write("{0} ", i);
}
}
Console.ReadLine(); //the above was mistake, but I kept it ;)
Console.Write("Enter a Number: ");
int userNum = Convert.ToInt32(Console.ReadLine());
long factNum = 1;
for (int i = userNum; i > 0; i--)
{
if (i == 1)
{
Console.Write(i);
}
else
{
Console.Write("{0} x ", i);
}
factNum *= i;
}
Console.WriteLine(" = {0}", factNum);
Console.ReadLine();
This is relatively easy, but I couldn't get a grasp of it until I nearly snapped.
Oh well all fine now :)
Il-Ħamis, Settembru 25, 2008
Subscribe to:
Posts (Atom)