-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointerarrayswap2.c
More file actions
43 lines (43 loc) · 889 Bytes
/
pointerarrayswap2.c
File metadata and controls
43 lines (43 loc) · 889 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 a;
printf("Enter the size of array: \n");
scanf("%d",&a);
int arr1[a];
int arr2[a];
int *p;
int *p1,*p2;
p=arr1;
int temp[a];
printf("enter the array elements: \n");
for(int i=0;i<a;i++)
{
scanf("%d",(p+i));
}
p1=arr2;
printf("enter the array elements: \n");
for(int i=0;i<a;i++)
{
scanf("%d",(p1+i));
}
p2=temp;
for(int i=0;i<a;i++)
{
*(p2+i)=*(p+i);
*(p+i)=*(p1+i);
*(p1+i)=*(p2+i);
}
printf("\nSwap the 2nd array elements in first array are:\n");
for(int i=0;i<a;i++)
{
printf("%d ",*(p+i));
}
p1=arr2;
printf("\nSwap the 1st array elements in 2nd array are:\n");
for(int i=0;i<a;i++)
{
printf("%d ",*(p1+i));
}
return 0;
}