Write a program to print all the elements of an array in forward and backward order using single loop. ARRAY is 1,2,3,4,5 output should be 1,2,3,4,5,5,4,3,2,1
Ahmar Husain
Select an image from your device to upload
int[] arr = { 1, 2, 3, 4, 5 }; string a=””; string b=””; for (int i = 0; i < arr.Length; i++) {
a=a+arr[i].ToString(); b=b+arr[arr.Length-i-1].ToString(); } Console.WriteLine(a); Console.WriteLine(b);
a=a+arr[i].ToString();
b=b+arr[arr.Length-i-1].ToString();
}
Console.WriteLine(a);
Console.WriteLine(b);