Write a program to swap the elements of two given arrays

Source Code

#include<stdio.h>
#include<conio.h>
int main (int argc, char *argv[])
{
  clrscr();
  int ar[100];
  int ar2[100];
  int r1,r2,i,t=0,l;
  for(i=0;i<100;i++)
  {
    ar[i]=0;
    ar2[i]=0;
  }
  printf("\n Enter the range of two arrays:(less than 100) ");
  scanf("%d %d",&r1,&r2);
  printf("\n Enter the elements of the first array:");
  for(i=0;i<r1;i++)
  {
       printf("\n Enter element number: %d ",(i+1));
       scanf("%d",&ar[i]);
  }
  printf("\n Enter the elements of the second array:");
  for(i=0;i<r2;i++)
  {
       printf("\n Enter element number: %d ",(i+1));
       scanf("%d",&ar2[i]);
  }
  if(r1<r2)
    l=r1;
  else
    l=r2;
  for(i=0;i<l;i++)
  {
         t=ar[i];
         ar[i]=ar2[i];
         ar2[i]=t;
  }
  printf("\n The swapped arrays are: \nfirst second \n");
  for(i=0;i<l;i++)
  {
    printf("%d ",ar[i]);
    printf("%d ",ar2[i]);
    printf("\n");
  }
  getch();
}

Find More from our code collection
Armstrong number, binary number to a decimal number, bubble sort, decimal number to binary number, factorial of the given number factors, fibonacci numbers, HCF and LCM, matrix, mergesort, salary of the employee. palindrome, quadratic equation, star patterns, series etc. and much more...
#Return to Example Source Code