+ 2
Please Fix this Code--Factorial of the Arrays
2 odpowiedzi
+ 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...
+ 1
Thank you Sir #ValentinHacker