-
Notifications
You must be signed in to change notification settings - Fork 0
/
100-print_comb3.c
executable file
·41 lines (36 loc) · 1 KB
/
100-print_comb3.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
#include <stdio.h>
/**
* main - Prints all possible different combinations of two digits
*
* Description: This program will print all unique combinations of two digits
* in ascending order separated by a comma followed by a space. The two digits
* must be different - 01 and 10 are considered the 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 digits */
for (i = 0; i < 10; i++)
{
for (j = i + 1; j < 10; j++)
{
/* Print the first digit */
putchar(i + '0');
/* Print the second digit */
putchar(j + '0');
/* Print comma and space after all combinations except last one */
if (!(i == 8 && j == 9))
{
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);
}