Menus

Saturday 22 October 2022

How to Swap Two Arrays In C Language

 

#include<stdio.h>

void main()

{


  int a[5] = {5,6,7,8,9};

  int b[5] = {1,2,3,4,5};

  

  int i,swap;


  for(i=0;i<5;i++)

  {


    swap = a[i];

    a[i] = b[i];

    b[i] = swap;


  } 


  printf("A = ");

  for(i=0;i<5;i++)

    printf("%d ",a[i]);


  printf("\nB = ");

  for(i=0;i<5;i++)

    printf("%d ",b[i]); 


  printf("\n");

}







No comments:

Post a Comment