728x90
반응형
#include <stdio.h>

void swap(int* pa, int* pb);
void line_up(int* px, int* pd, int* pn);
//void test(int* px, int* pd, int* pn);

int main(void)
{
	int max, mid, min;

	printf("정수값 세개 입력 : ");
	scanf_s("%d%d%d", &max, &mid, &min);

	line_up(&max, &mid, &min);

	//test(&max, &mid, &min);

	printf("%d, %d, %d\n", max, mid, min);

	return 0;
}

void swap(int* pa, int* pb)
{
	int temp;

	temp = *pa;
	*pa = *pb;
	*pb = temp;
}


/*
void test(int* px, int* pd, int* pn)
{
	*px = 3;
	*pd = 2;
	*pn = 1;
}
*/


void line_up(int* px, int* pd, int* pn)		// &max, &mid, &min
{
	if (*px < *pd)
	{
		swap(px, pd);		// pointer var addr = px / NOT &px ******
	}

	if (*px < *pn)
	{
		swap(px, pn);
	}

	if (*pd < *pn)
	{
		swap(pd, pn);
	}
}
728x90
반응형

'Language > C & C++' 카테고리의 다른 글

the difference between Parameter and Argument  (0) 2022.08.30
Tip for arrays  (0) 2022.08.29
C_10. Basic Grammar of Structure  (0) 2022.08.15
C_09. Basic Grammar of Function  (0) 2022.08.12
C_08. Basic Grammar of Pointer  (0) 2022.08.11

+ Recent posts