EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+
 

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++)
10    {
11      ar[i]=0;
12      ar2[i]=0;
13    }
14    printf("\n Enter the range of two arrays:(less than 100) ");
15    scanf("%d %d",&r1,&r2);
16    printf("\n Enter the elements of the first array:");
17    for(i=0;i<r1;i++)
18    {
19         printf("\n Enter element number: %d ",(i+1));
20         scanf("%d",&ar[i]);
21    }
22    printf("\n Enter the elements of the second array:");
23    for(i=0;i<r2;i++)
24    {
25         printf("\n Enter element number: %d ",(i+1));
26         scanf("%d",&ar2[i]);
27    }
28    if(r1<r2)
29      l=r1;
30    else
31      l=r2;
32    for(i=0;i<l;i++)
33    {
34           t=ar[i];
35           ar[i]=ar2[i];
36           ar2[i]=t;
37    }
38    printf("\n The swapped arrays are: \nfirst second \n");
39    for(i=0;i<l;i++)
40    {
41      printf("%d ",ar[i]);
42      printf("%d ",ar2[i]);
43      printf("\n");
44    }
45    getch();
46  }

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