محاسبه فاکتوریل یک عدد
سوال
برنامه ای بنویسید ک یک عدد به عنوان ورودی گرفته وفاکتوریل ان را بدست اورد
در حال بررسی
0
انجمن برنامه نویسان سی شارپ
4 سال
7 پاسخ ها
9491 دیده شده
2
پاسخ ها ( ۷ )
Console.WriteLine(“enter number”);
int number = Convert.ToInt32(Console.ReadLine());
int f = fact(number);
Console.WriteLine(“factorial:”+f);
}
public static int fact(int n)
{
if (n==1)
{
return 1;
}
else
{
return n * fact(n – ۱);
}
سلام وقت بخیر،
int fact = 1;
int num;
int i;
num = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= num; i++)
{
fact = fact * i;
}
Console.WriteLine(“fact:” + fact);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Prj_1
{
class Program
{
static void Main(string[] args)
{
int fact = 1, num;
Console.WriteLine(“enter a number”);
num = int.Parse(Console.ReadLine());
for(int i = 1; i <= num; i++)
{
fact *= i;
}
Console.WriteLine("{0}! = {1}", num, fact);
Console.ReadKey();
}
}
}