-
Notifications
You must be signed in to change notification settings - Fork 0
/
102-print_comb5.c
48 lines (43 loc) · 1.03 KB
/
102-print_comb5.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
#include <stdio.h>
/**
* main - main block
* Description: Print all possible combinations of two two-digit numbers.
* Numbers should range from 0 to 99.
* The two numbers should be separated by a space.
* All numbers should be printed with two digits. 1 should be printed as 01.
* Combination of numbers must be separated by a comma followed by a space.
* Combinations of numbers should be printed in ascending order.
* `00 01` and `01 00` are considered as the same combination.
* You can only use `putchar` up to 8 times.
* Return: 0
*/
int main(void)
{
int i, j;
int a, b, c, d;
for (i = 0; i < 100; i++)
{
a = i / 10; /* doubles fnum */
b = i % 10; /* singles fnum */
for (j = 0; j < 100; j++)
{
c = j / 10; /* doubles snum */
d = j % 10; /* singles snum */
if (a < c || (a == c && b < d))
{
putchar(a + '0');
putchar(b + '0');
putchar(32);
putchar(c + '0');
putchar(d + '0');
if (!(a == 9 && b == 8))
{
putchar(44);
putchar(32);
}
}
}
}
putchar(10);
return (0);
}