Search code examples
c#sumfactorialprocedures

sum of the factorial number tell the procedure of each number


i did a code to factorial to work and sum but i dont know how to tell the procedure the proffesor want from me to tell him the output like this : 6!=1*2*3*4*5*6=720 but i dont know how to do this i am stuck i am newbee and its my first year at school, my output is : "Numri Faktorial i 6 eshte 720" i did it this way because i dont know the way that ask on school i need help (ps = sory for my bad english :( ) my code is :

int i, numri, faktorieli;
Console.WriteLine("Shtype numrin : "); 
numri = int.Parse(Console.ReadLine());
faktorieli = numri;
for (i = numri - 1; i >= 1; i--)
{
    faktorieli = faktorieli * i;
}
Console.WriteLine("\nNumri Faktorial i {0} eshte {1}: ", numri, faktorieli);
Console.ReadLine();

Solution

  • You could try something like this:

    var factorialExpression = string.Join("*", Enumerable.Range(1,numri));
    Console.WriteLine("{0}!={1}={2}", numri, factorialExpression, faktorieli);
    

    Update

    In order to not use this code, without understanding how it works, you should have a look at the following links for the start: