Koding C# Menghitung Nilai Faktorial
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication31
{
class Program
{
static void Main(string[] args)
{
int n, k, fak;
Console.WriteLine("SELAMAT
DATANG DIPROGRAM INI ");
Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
Console.Write("
SilakanMasukkan Nilai N :");
double hasil = 0.00;
string soal = "";
n
= Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Menghitung
Hasil Faktorial : ");
for (int i = 1; i
<= n; i++)
{
if (i == 1)
{
soal = "1/" + i + "!";
}
else
{
soal = soal + " + " + "1/" + i + "!";
}
fak = 1;
for (k = 1; k <= i; k++)
{
fak = fak * k;
}
hasil = hasil + (1 / Convert.ToDouble(fak));
//Console.WriteLine(hasil);
}
Console.WriteLine(soal + "
= " + hasil);
Console.ReadLine();
}
}
}
0 komentar: