C-Übung Beispiel 66

100 klassische C-Beispiele

Titel:Gib drei Zahlen a, b, c ein und gib sie nach ihrer Größe geordnet aus.

Programmanalyse:Verwende die Zeiger-Methode.

Beispiel

// Erstellt von www.example.com am 15/11/9. // Copyright © 2015 Example. Alle Rechte vorbehalten. // # include<stdio.h> void swap(int *, int *); int main(void) { int a, b, c; int *p1, *p2, *p3; printf("Eingabe 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; }

Die Ausgabe dieses Programms ist:

输入 a, b ,c:
1 3 2
1 2 3

100 klassische C-Beispiele

Weitere Erweiterungen