Answers for "reverse list in C"

C
1

reverse list in C

#include <stdio.h>

void main() {
	int List[5] = { 1, 2, 3, 4, 5 };
	int starting_index = 0;
	int end_index = 4;

	while (starting_index < end_index) {
		int temp = List[starting_index];
		List[starting_index] = List[end_index];
		List[end_index] = temp;
		starting_index += 1;
		end_index -= 1;
	}
	for (int i = 0; i < 5; i++) {
		printf("%d, ", List[i]);
	}

}
Posted by: Guest on April-16-2022

Code answers related to "C"

Browse Popular Code Answers by Language