Skip to content

Instantly share code, notes, and snippets.

@zapstar
Created March 9, 2015 12:26
Show Gist options
  • Save zapstar/2e0e3eea8de029417d2d to your computer and use it in GitHub Desktop.
Save zapstar/2e0e3eea8de029417d2d to your computer and use it in GitHub Desktop.
Find the two largest numbers among the three.
#include <stdio.h>
void max2(int a, int b, int c) {
int first, second;
printf("a = %d, b = %d, c = %d\n", a, b, c);
if (a > b) {
second = a;
if (a > c) {
first = a;
if (b > c) {
second = b;
} else {
second = c;
}
} else {
first = c;
}
} else {
second = b;
if (b > c) {
first = b;
if (a > c) {
second = a;
} else {
second = c;
}
} else {
first = c;
}
}
printf("first = %d, second = %d\n", first, second);
}
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
max2(a, b, c);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment