Test/C

숫자이동 프로그램

kiostory 2017. 8. 8. 15:14

1,2,3으로 초기화된 변수의 값을 하나씩 왼쪽으로 이동하며 출력.

엔터가 아닌값을 넣으면 종료


#include <stdio.h>
#include <stdlib.h>

void rotate(int *pa, int *pb, int *pc);

int main(void)

{
    int a=1, b=2, c=3;
    char input;

    while(1)
    {
        rotate(&a,&b,&c);
        scanf("%c",&input);
        if(input!='\n') break;

    }

    return 0;

}

void rotate(int *pa, int *pb, int *pc)
{
    int temp;

    printf("%d:%d:%d",*pa,*pb,*pc);

    temp=*pa;
    *pa=*pb;
    *pb=*pc;
    *pc=temp;

}
-----------------------------------------------------------

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:2x

Process returned 0 (0x0)   exe
Press any key to continue.