Test/C
숫자 로테이션
kiostory
2019. 5. 22. 23:35
[1,2,3이 로테이션되며 출력]
#include<stdio.h>
void rotate(int *a,int *b,int *c);
int main(void)
{
int a=1, b=2, c=3;
char key;
do
{
printf("%d:%d:%d",a,b,c);
scanf("%c",&key); // 또는 key=getchar();
rotate(&a,&b,&c);
}while(key == '\n');
return 0;
}
void rotate(int *a,int *b,int *c)
{
int nTemp=*a;
*a=*b;
*b=*c;
*c=nTemp;
}
--------------------------------
처음 한줄이 나오고 엔터치면 계속 로테이션, 문자 입력후 엔터치면 종료
1:2:3
2:3:1
3:1:2
1:2:3
2:3:1
3:1:2
1:2:3
2:3:1
3:1:2
1:2:3a
(종료)