-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathArray reverse
More file actions
41 lines (39 loc) · 789 Bytes
/
Array reverse
File metadata and controls
41 lines (39 loc) · 789 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
2 Array
#include<stdio.h>
int main() {
int n,L,r,temp,i,j;
scanf("%d",&n);
int a[n],b[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
i=0,j=n-1;
while(i<n&&j>=0)
{
b[i]=a[j];
j--;
i++;
}
for(i=0;i<n;i++)
printf("%d ",b[i]);
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Single Array
#include<stdio.h>
int main() {
int n,L,r,temp,i,j;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
scanf("%d",&a[i]);
i=0,j=n-1;
while(i<j)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
j--;
i++;
}
for(i=0;i<n;i++)
printf("%d ",a[i]);
}