c code to swap three numbers

  • c
  • write a c code to swap three numbers

    Write a program that takes three variables (a, b, c) as separate parameters and rotates the values stored so that value a goes to be, b, b to c, and c to a by using SWAP(x,y) a function that swaps/exchanges the numbers x & y.

    Code

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> void refrenceswap(int *a, int *b) { int temp; temp = *a; *a = *b; *b = temp; } int main() { clock_t t; t = clock(); int a, b, c; printf("enter the three numbers to swap\n"); scanf("%d", &a); scanf("%d", &b); scanf("%d", &c); int tempa = a; printf("the value of a and b and c are : %d and %d and %d\n", a, b, c); refrenceswap(&a, &b); refrenceswap(&b, &c); refrenceswap(&c, &tempa); printf("the value of a and b and c are : %d and %d and %d\n", a, b, c); t = clock() - t; double time_taken = ((double)t) / CLOCKS_PER_SEC; printf("\nfun() took %f seconds to execute \n", time_taken); return 0; }