How to swap three numbers in cycle order with C

1 Answer

0 votes
#include <stdio.h>  

void CycleSwap(int *a, int *b, int *c);
  
int main(void)
{   
    int a = 1, b = 2, c = 3;

    printf("a = %d b = %d c = %d\n",a, b, c);
    
    CycleSwap(&a, &b, &c);

    printf("a = %d b = %d c = %d\n",a, b, c);
      
    return 0;
}
void CycleSwap(int *a, int *b, int *c)
{

    int tmp;

    tmp = *b;
    *b = *a;
    *a = *c;
    *c = tmp;
}
  
          
/*
run:
       
a = 1 b = 2 c = 3
a = 3 b = 1 c = 2
 
*/

 



answered May 25, 2017 by avibootz
...