我如何以表格格式(图表)放置此代码? [英] How would I put this code in tabular format (a chart)?
问题描述
喜欢,我需要将这些代码放在一个表格格式中,提示用户输入一个数字来查找随后显示的阶乘,用户输入的数字以及该数字的阶乘。但我需要图表有6行。第一行作为标题,接下来的五行是因子转换(用户输入的数字以及输入的数字的阶乘)。我只需要第一到第五的阶乘。
使用系统;
使用System.Collections.Generic;
使用System.Text;
命名空间ConsoleApplication1
{
班级课程
{
< br $>
static int Fact(int n)
{
if(n < = 1)
返回1;
返回n *事实(n - 1);
}
静态如果(n <= 1)
>
返回1;
int result = 1;
{
for(int i = 2; i< = n; i ++)
result = result * i;
}
返回结果;
}
static void Main(string [] args)
$
Console.Write("输入数字以查找阶乘:");
int n = Convert.ToInt32(Console.ReadLine());
int r = Fact(n);
Console.WriteLine(n.ToString()+" ! = + r.ToString());
Console.Write("输入一个数字到find factorial:");
n = Convert.ToInt32(Console.ReadLine());
r = Factorial(n);
Console.WriteLine(n.ToString()+"!=" + r.ToString());
Console.Write("输入一个数字来查找阶乘:");
n = Convert.ToInt32 (Console.ReadLine());
r = Factorial(n);
Console.WriteLine( n.ToString()+"!=" + r.ToString());
Console.Write("输入一个数字来查找阶乘:" ;);
n = Convert.ToInt32(Console.ReadLine());
r = Factorial( n);
Console.WriteLine(n.ToString()+" ! = + r.ToString());
Console.Write("输入一个数字来查找阶乘:");
n = Convert.ToInt32(Console.ReadLine());
r = Factorial(n);
Console.WriteLine(n.ToString()+"!=" + r.ToString());
Console.ReadLine();
}
}
}
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();
}
}
}
推荐答案
请不要在多个论坛中发布相同的问题。
Please do not post the same question in multiple forums.
这篇关于我如何以表格格式(图表)放置此代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!