Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions 0x01-variables_if_else_while/102-print_comb5.c
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
/*
* File: 102-print_comb5.c
* Auth: Brennan D Baraban
*/

#include <stdio.h>

/**
* main - Prints all possible combinations of two two-digit numbers,
* ranging from 0-99, separated by a comma followed by a space.
*
* Return: Always 0.
*main - print a num pair from 00-99 but no repeats (00 01, 00 02, 00 03,...)
*Return: Always 0 (Success)
*/

int main(void)
{
int num1, num2;
int tens;
int units;
int t;
int u;

for (num1 = 0; num1 <= 98; num1++)
for (tens = '0'; tens <= '9'; tens++) /*print first two digit combo*/
{
for (num2 = num1 + 1; num2 <= 99; num2++)
for (units = '0'; units <= '9'; units++)
{
putchar((num1 / 10) + '0');
putchar((num1 % 10) + '0');
putchar(' ');
putchar((num2 / 10) + '0');
putchar((num2 % 10) + '0');

if (num1 == 98 && num2 == 99)
continue;

putchar(',');
putchar(' ');
}
}
for (t = tens; t <= '9'; t++) /*print second of pair*/
{
for (u = units + 1; u <= '9'; u++)
{
putchar(tens);
putchar(units);
putchar(' ');
putchar(t);
putchar(u);

if (!((tens == '9' && units == '8') &&
(t == '9' && u == '9')))
{
putchar(','); /* inserting commas */
putchar(' ');
} /* end of IF statement */
} /* end of last FOR loop */
} /* end of second to last loop */
} /* end of the second loop */
} /* end of the nested loop */
putchar('\n');

return (0);
}
} /* end of main */