|
|
Suchschleife
A05.cs
using System;
class Test {
static int IndexOf(int val, int[] tab) {
int i = tab.Length - 1;
while (i >= 0 && tab[i] != val) i--;
return i;
}
static void Main() {
int[] tab = {3, 6, 14, 4, 12, 9, 10, 1, 5};
Console.WriteLine(IndexOf(3, tab));
Console.WriteLine(IndexOf(5, tab));
Console.WriteLine(IndexOf(12, tab));
Console.WriteLine(IndexOf(7, tab));
}
}
|
|