reverse array in c

Solutions on MaxInterview for reverse array in c by the best coders in the world

showing results for - "reverse array in c"
Hyacinth
03 Jan 2018
1a = [1,2,3,4]
2a = a[::-1]
3print(a)
4>>> [4,3,2,1]
Sean
22 Feb 2020
1#include <iostream>
2using namespace std;
3int main()
4{		// While loop
5	const int SIZE = 9;
6	int arr [SIZE];
7	cout << "Enter numbers: \n";
8	for (int i = 0; i < SIZE; i++)
9		cin >> arr[i];
10	for (int i = 0; i < SIZE; i++)
11		cout << arr[i] << "\t";
12	cout << endl;
13	cout << "Reversed Array:\n";
14	int temp, start = 0, end = SIZE-1;
15	while (start < end)
16	{
17		temp = arr[start];
18		arr[start] = arr[end];
19		arr[end] = temp;
20		start++;
21		end--;
22	}
23	for (int i = 0; i < SIZE; i++)
24		cout << arr[i] << "\t";
25	cout << endl;	
26  	return 0;
27}
28
Ella
07 Aug 2019
1// arr is the array
2// a is length of array
3int j = a-1;
4for(int i = 0; i<j; i++){
5	arr[i]^=arr[j];
6    arr[j]^=arr[i];
7    arr[i]^=arr[j];
8    j--;
9}
Giuseppe
22 Nov 2020
1>>> L = [0,10,20,40]
2>>> L[::-1]
3[40, 20, 10, 0]
Odele
31 Nov 2016
1import java.util.Arrays;
2public class ReverseStringArrayInJava
3{
4   public static void main(String[] args)
5   {
6      String[] strHierarchy = new String[]{"Junior Developer","Senior Developer","Team Lead","Project Manager","Senior Manager","CEO"};
7      System.out.println("Given string array: " + Arrays.toString(strHierarchy));
8      for(int a = 0; a < strHierarchy.length / 2; a++)
9      {
10         String strTemp = strHierarchy[a];
11         strHierarchy[a] = strHierarchy[strHierarchy.length - a - 1];
12         strHierarchy[strHierarchy.length - a - 1] = strTemp;
13      }
14      System.out.println("Reversed string array: ");
15      for(int a = 0; a < strHierarchy.length; a++)
16      {
17         System.out.println(strHierarchy[a]);
18      }
19   }
20}
similar questions
queries leading to this page
reverse array in c