6th Feb 2018, 1:08 PM
VIKAS
VIKAS - avatar
2 Answers
+ 8
foreach(int k in a){ Console.WriteLine(Fact(a[k])); } //"k in a" means that k will hold the value of a[iteration] and NOT the index itself... you must get value like "k" and not "a[k]" //for example, on first run k is (a[0]) 1 and you do a[k] (a[1]), the second element of a is 2 (you actually skip first value like this)... the error occurs because you try to get a value outside of the array length, if a has 5 elements a[5] will throw an error...
6th Feb 2018, 1:12 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 1
Thank you Sir #ValentinHacker
6th Feb 2018, 1:22 PM
VIKAS
VIKAS - avatar