Daily Learning | Basic Training in C Language

Daily Learning | Basic Training in C Language

Problem:

Example 066

Problem: Input three numbers a, b, c, and output them in order of size.

Program Analysis: Use pointer method.

NEXT

Daily Learning | Basic Training in C LanguageDaily Learning | Basic Training in C Language

Solution:

# include<stdio.h>

void swap(int *, int *);

int main(void)

{

int a, b, c;

int *p1, *p2, *p3;

printf(“Input a, b, c:\n”);

scanf(“%d %d %d”, &a, &b, &c);

p1 = &a;

p2 = &b;

p3 = &c;

if(a>b)

swap(p1, p2);

if(a>c)

swap(p1, p3);

if(b>c)

swap(p2, p3);

printf(“%d %d %d\n”, a, b, c);

}

void swap(int *s1, int *s2)

{

int t;

t = *s1; *s1 = *s2; *s2 = t;

}

NEXT

Daily Learning | Basic Training in C LanguageDaily Learning | Basic Training in C Language

The output result of the above code is:

Input a, b, c:

1 3 2

1 2 3

END

Daily Learning | Basic Training in C Language

June 3, 2025, Tuesday

Be diligent and achieve self-improvement

Layout | Gu Yongjian

Typesetting | Gu Yongjian

Editor | Han Xinran, Zeng Xiangyu

Review | Shi Ling, Qiao Shan

Daily Learning | Basic Training in C Language

Leave a Comment