-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPat-2.c
74 lines (59 loc) · 1.26 KB
/
Pat-2.c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*PAT-2
Write a C program to reverse the elements of an integer array and store them in another array. Compare the elements of these two arrays. If the elements in both the arrays are the same print "EQUAL" else print "NOT EQUAL".
Should dynamically allocate memory for the array depending upon the number of elements to be stored.
Use pointers to deal with the array elements.
Eg.
Input:
Enter number of elements in array1
Enter the elements in array1
Output:
EQUAL/NOT EQUAL
Sample Input:
5
5 8 10 8 5
Output:
EQUAL*/
//Code:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *a,*b,*temp1,*temp2,n,val=1,i,j;
scanf("%d",&n);
a=(int*)malloc(n*sizeof(int));
b=(int*)malloc(n*sizeof(int));
temp1=a;
for (i=0;i<n;i++)
{
scanf("%d", &temp1);
temp1++;
}
temp1--;
temp2=b;
for (int i=0;i<n;i++)
{
*temp2=*temp1;
temp2++;
temp1--;
}
temp1=a;
temp2=b;
for(i=0;i<n;i++)
{
if(*temp1!=*temp2)
{
val=0;
break;
}
else
{
temp1++;
temp2++;
}
}
if(val==1)
printf("EQUAL");
else
printf("NOT EQUAL");
return 0;
}