-
Notifications
You must be signed in to change notification settings - Fork 0
/
triplet_finder.c
54 lines (43 loc) · 1.23 KB
/
triplet_finder.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
int main() {
int first = 0, second = 0, third = 0, given = 1, count = 0;
while (given != 0){
if (third > second && second > first && ((first != 0 && second != 0) && third != 0 )){
count += 1;
printf("Triplet #%d : %d, %d, %d\n", count, first, second, third);
}
printf("Give a number: ");
scanf("%d", &given);
if (first == 0){
first = given;
} else if (second == 0){
second = given;
if (first > second){
first = second;
second = 0;
}
} else if (third == 0){
third = given;
if (second > third){
first = third;
second = 0;
third = 0;
}
}
else {
if (given > third){
first = second;
second = third;
third = given;
} else{
first = given;
second = 0;
third = 0;
}
}
}
if (given == 0){
printf("The program has ended.\n");
return 0;
}
}