-4

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();
Christos
  • 53,228
  • 8
  • 76
  • 108
  • A `Console.Write` inside the `for` and inverting the `for` to go from `0` to `numri` would help you to give the output your professor wants. – GGG Nov 16 '16 at 19:52
  • he want me to tell the procedure i mean he want if i type a 6 to factorial : 6! = 1*2*3*4*5*6=720 he want more details output :( – Diar Kryeziu Nov 16 '16 at 19:54
  • An alternative would be to create a StringBuilder that you can update during the loop, and then you can set the output using StringBuilder.ToString(). This approach, in my mind, is easier from a debugging point of view because you can see the current output in your IDE versus swapping between the console window and the IDE as you cycle through breakpoints. – Chris Thompson Nov 16 '16 at 19:55
  • 1
    @DiarKryeziu with the `Console.Write` inside the `for` loop you can print each number individually thus giving the detailed output he wants. As `Console.Write` doesn't puts a line terminator in the end, you can print out each number. – GGG Nov 16 '16 at 19:56
  • @DiarKryeziu I edited your post. It's not a perfect edit, but an effort you have a shorter title (I admit no the best one) and well formatted code. Keep in mind that both of them are very important, in order your question to be readable by others and you get sooner rather than later a response. Last bust not least, you should also try to point out what you have tried and where you get stuck. This is just my 2 cents. – Christos Nov 16 '16 at 20:07

1 Answers1

2

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:

Christos
  • 53,228
  • 8
  • 76
  • 108
  • It's still not quite clear what the OP wants, but if I had to guess, I'd say this is it. – Gavin Nov 16 '16 at 19:55
  • 1
    spoon feeding is bad – Vivek Nuna Nov 16 '16 at 19:55
  • 4
    This works, but we are writing his homework for him and he is learning nothing. Hopefully he copies and pastes your code then the TA and teacher will know immediately he copied it and give him a zero because he clearly has no idea what `string.Join` or `Enumerable.Range` are and they will stick out like a sore thumb. – Quantic Nov 16 '16 at 19:56
  • @Quantic If you hadn't shown any effort, about how to calculate the factorial, I wouldn't have provided any suggestion. Hopefully, He should search for `string.Join` and `Enumerable.Range`, in order to avoid the copy/paste. – Christos Nov 16 '16 at 19:57
  • ohhhh thank you this was what i was looking thank you – Diar Kryeziu Nov 16 '16 at 19:57
  • @Christos Simply giving the answer is not a "suggestion", its plain spoon feeding. – GGG Nov 16 '16 at 19:58
  • but anyway he is rght i dont know what is string.join :( if he ask me so uff – Diar Kryeziu Nov 16 '16 at 19:58
  • @DiarKryeziu for this reason I updated my post. Please read about them and if you have any question search it and if you don't find an answer come back and ask :) – Christos Nov 16 '16 at 20:00
  • @DiarKryeziu Although this answer is nice, it's something that comes with experience and knowledge. It may be better if you keep this trick in your pocket, but use one or more of the suggestions on your question to solve your problem. – Gavin Nov 16 '16 at 20:03