Swapping two arrays

Swapping of two arrays

Swapping two arrays

In this article, We are going to learn, C Program to Swap two Arrays.

/* C Program to Swap Two Arrays Without Using Temp Variable */
#include<stdio.h>
#include<conio.h>
void main()
{
 int Size, i, x[10], y[10], Temp[10];
  printf("\n\t\t\t...Welcome To EduNews.Tech... ");

 printf("\n\nPlease Enter the Size of the Array :\n");
 scanf("%d", &Size);
 
 printf("\nPlease Enter the First Array Elements :\n");
 for(i = 0; i < Size; i++)
  {
      scanf("%d", &x[i]);
  }
   
 printf("\nPlease Enter the Second Array Elements :\n");
 for(i = 0; i < Size; i ++)
  {
      scanf("%d", &y[i]);
  }

 //Swapping two Arrays 
 for(i = 0; i < Size; i++)
  {
    x[i] = x[i] + y[i];
    y[i] = x[i] - y[i]; 
    x[i] = x[i] - y[i];
  }

 printf("\n x[%d] Array Elements After Swapping :\n", Size); 
 for(i = 0; i < Size; i ++)
  {
      printf(" %d \t ",a[i]);
  }

printf("\n\n y[%d] Array Elements After Swapping :\n", Size); 
 for(i = 0; i < Size; i ++)
  {
      printf(" %d \t ",y[i]);
  }
printf("\n\n\n\t\t\tThankyou for Joining Us !");
    printf("\n\t\t\t!Regards EduNews !");

  getch();
}

Program Output:

swapping arrays

I hope this post helps you to understand the Program that how to “Swap two arrays” and its implementation in C programming language.

Keep coding 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *