forked from Nikhil-2002/Programming_Hactoberfest25
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse_an_array.c
More file actions
43 lines (33 loc) · 882 Bytes
/
Copy pathreverse_an_array.c
File metadata and controls
43 lines (33 loc) · 882 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <stdio.h>
int main() {
int size;
// Taking the size of the array from the user
printf("Enter the size of the array: ");
scanf("%d", &size);
if (size <= 0) {
printf("Invalid size\n");
return 1; // Exit the program with an error code
}
int arr[size];
// Taking array elements as input from the user
printf("Enter the elements of the array:\n");
for (int i = 0; i < size; ++i) {
scanf("%d", &arr[i]);
}
// initializing the start and end position of an array.
int start=0;
int end=size-1;
// Reversing the array
while(start<end){
int temp=arr[start];
arr[start]=arr[end];
arr[end]=temp;
start++;
end--;
}
// Printing the Reversed array
for (int i = 0; i < size; i++) {
printf("%d ", arr[i]);
}
return 0;
}