Click here to Skip to main content
15,912,082 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Like, I need to put this code in a tabular format that prompt user to enter a number to find the factorial that then display, the number entered by the user as well as the factorial of that number. But I need the chart to have 6 lines. The first line as a header and the next five lines is for the factorial conversions (the number entered by the user as well as the factorial of that number entered). I only need the factorial of number one through five.

using System;

using System.Collections.Generic;

using System.Text;



namespace ConsoleApplication1
{

class Program
{



static int Fact(int n)
{

if (n <= 1)

return 1;

return n * Fact(n - 1);

}



static int Factorial(int n)
{

if (n <= 1)

return 1;

int result = 1;


{
for (int i = 2; i <= n; i++)
result = result * i;

}

return result;

}





static void Main(string[] args)
{





Console.Write("Enter a Number to find factorial: ");

int n = Convert.ToInt32(Console.ReadLine());

int r = Fact(n);

Console.WriteLine(n.ToString() + "! = " + r.ToString());



Console.Write("Enter a Number to find factorial: ");

n = Convert.ToInt32(Console.ReadLine());

r = Factorial(n);

Console.WriteLine(n.ToString() + "! = " + r.ToString());

Console.Write("Enter a Number to find factorial: ");

n = Convert.ToInt32(Console.ReadLine());

r = Factorial(n);

Console.WriteLine(n.ToString() + "! = " + r.ToString());

Console.Write("Enter a Number to find factorial: ");

n = Convert.ToInt32(Console.ReadLine());

r = Factorial(n);

Console.WriteLine(n.ToString() + "! = " + r.ToString());

Console.Write("Enter a Number to find factorial: ");

n = Convert.ToInt32(Console.ReadLine());

r = Factorial(n);

Console.WriteLine(n.ToString() + "! = " + r.ToString());


Console.ReadLine();
}

}

}
Posted
Updated 18-Apr-13 14:58pm
v2
Comments
rmksiva 15-Apr-13 23:50pm    
Can You Please Elaborate ? Make Tabular Code or Program result ?
Sergey Alexandrovich Kryukov 16-Apr-13 0:26am    
Agree. Right now, the question does not seem to make whole lot of sense. OP is recommended to use "Improve question", above.
—SA

1 solution

Please do not post the same question in multiple forums.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900