0% found this document useful (0 votes)
2 views1 page

Reverse Array in C Programming

The document contains a C program that reverses a portion of an array based on a user-defined split index. It prompts the user for the number of elements, the elements themselves, and the split index, then performs two reverse operations on the array. Finally, it prints the modified array to the console.

Uploaded by

amoghpanthangi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Reverse Array in C Programming

The document contains a C program that reverses a portion of an array based on a user-defined split index. It prompts the user for the number of elements, the elements themselves, and the split index, then performs two reverse operations on the array. Finally, it prints the modified array to the console.

Uploaded by

amoghpanthangi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1: #include <stdio.

h>
2:
3: void reverse(int *p, int m, int n)
4: {
5: int i, t;
6: for(i=0; i<=(n-m)/2; i++)
7: {
8: t = *(p+m+i);
9: *(p+m+i) = *(p+n-i);
10: *(p+n-i) = t;
11: }
12: }
13:
14: int main()
15: {
16: int n, l, i;
17: printf("Enter no. of elements in the array : ");
18: scanf("%d", &n);
19: int arr[n];
20: printf("Enter elements of the array : ");
21: for(i=0; i<n; i++)
22: {
23: scanf("%d", &arr[i]);
24: }
25: printf("Enter split index : ");
26: scanf("%d", &l);
27: reverse(arr, l, n-1);
28: reverse(arr, 0, n-1);
29:
30: for(i=0; i<n; i++)
31: {
32: printf("%d ", arr[i]);
33: }
34: }
35:

You might also like