-
Notifications
You must be signed in to change notification settings - Fork 0
/
102-print_comb5.c
executable file
·46 lines (40 loc) · 1.24 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
#include <stdio.h>
/**
* main - Prints all possible different combinations of two two-digit numbers
*
* Description: Program will print all unique combinations of two two-digit
* numbers in ascending order separated by a comma followed by a space.
* Two numbers must be different - 01 02 and 02 01 are considered same
* combination.
*
* Return: 0 if successful, non-zero otherwise
*/
int main(void)
{
/* Variables to keep track of the digits */
int i, j;
/* Loop through all possible combinations of two two-digit numbers */
for (i = 0; i < 100; i++)
{
for (j = i + 1; j < 100; j++)
{
/* Print the first number */
putchar((i / 10) + '0'); /* first digit */
putchar((i % 10) + '0'); /* second digit */
putchar(' '); /* ASCII value for space */
/* Print the second number */
putchar((j / 10) + '0'); /* first digit */
putchar((j % 10) + '0'); /* second digit */
/* Print a comma and a space after all combinations except the last one */
if (!(i == 98 && j == 99))
{
putchar(','); /* ASCII value for comma */
putchar(' '); /* ASCII value for space */
}
}
}
/* Print a newline character after the last combination */
putchar('\n');
/* Return 0 to indicate successful execution */
return (0);
}