C Online Compiler
Example: C Program Swap Numbers in Cyclic Order using Call by Reference using Function
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C Program Swap Numbers in Cyclic Order using Call by Reference using Function #include <stdio.h> void swapCycle(int *p, int *q, int *r); // It's the driver function int main() { int p, q, r; // p, q & r - denotes the input numbers to swap in cyclic order printf("-----Enter the three numbers one by one-----\n"); scanf("%d %d %d", &p, &q, &r); printf("\n-----Values before swapping the numbers-----\n"); printf("p = %d \nq = %d \nr = %d\n", p, q, r); swapCycle(&p, &q, &r); printf("\n\n-----Values after swapping the numbers-----\n"); printf("p = %d \nq = %d \nr = %d\n", p, q, r); return 0; } // This function will swap the numbers itself void swapCycle(int *x, int *y, int *z) { int temp; // swapping in cyclic order temp = *y; *y = *x; *x = *z; *z = temp; }
2 5 7
Output
Clear
ADVERTISEMENTS