Answers for "swapping two array elements in c"

0

c program to swap two arrays

/* C Program to Swap Two Arrays Without Using Temp Variable */
#include<stdio.h>

int main()
{
 int Size, i, a[10], b[10], Temp[10];
  
 printf("\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", &a[i]);
  }
   
 printf("\nPlease Enter the Second Array Elements\n");
 for(i = 0; i < Size; i ++)
  {
      scanf("%d", &b[i]);
  }

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

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

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

  return 0;
}
Posted by: Guest on August-24-2020
0

swapping two array elements in c

swap array
Posted by: Guest on September-12-2021

Code answers related to "swapping two array elements in c"

Code answers related to "TypeScript"

Browse Popular Code Answers by Language