write a C program to reverse two array elements of the same size
as example if we have int a[]={1,2,3,4},int b[]={5,6,7,8}
after reversing we would have int a[]={5,6,7,8},int b[]={1,2,3,4}
as example if we have int a[]={1,2,3,4},int b[]={5,6,7,8}
after reversing we would have int a[]={5,6,7,8},int b[]={1,2,3,4}
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define size 4 | |
void swap(int *x1,int *x2) | |
{ | |
int temp=*x1; | |
*x1=*x2; | |
*x2=temp; | |
} | |
int main(int argc, char** argv) { | |
int a[size]={1, 2, 3, 4}; | |
int b[size]={5, 6, 7, 8}; | |
for(int j=0;j<size;j++) | |
{ | |
swap(&a[j],&b[j]); | |
} | |
printf("after reversing\n"); | |
for(int i=0;i<size;i++) | |
{ | |
printf("first array element %d\t%d\n",i,a[i]); | |
printf("second array element %d\t%d\n",i,b[i]); | |
} | |
return (EXIT_SUCCESS); | |
} |