SWAP 3 NUMBERS IN CYCLIC ORDER
Problem Description
Ramya, vidhya and Ramesh are always changing their places in cyclic manner. Can you write a code using methods(functions) to read 3 numbers and swap them using a temporary variable in a cyclic manner. Print the results in the specified order.
CODING ARENA
#include <stdio.h>
void cyclicswap(int *a,int *b,int *c);
int main()
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
cyclicswap(&a,&b,&c);
printf("%d\n%d\n%d\n",a,b,c);
return 0;
}
void cyclicswap(int *a,int *b,int *c)
{
int t;
t=*b;
*b=*a;
*a=*c;
*c=t;
}
Test Case 1
Input (stdin)1 2 3
Expected Output
3
1
2
Test Case 2
Input (stdin)4 5 6
Expected Output
6
4
5
No comments:
Post a Comment