Skip to content

Commit

Permalink
100-times_table.c
Browse files Browse the repository at this point in the history
  • Loading branch information
victorpreston committed Jun 20, 2023
1 parent a9f9212 commit d19c146
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Binary file not shown.
46 changes: 46 additions & 0 deletions 0x02-functions_nested_loops/100-times_table.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "main.h"
/**
* print_times_table - prints the n times table, starting with 0
* @n: number of the times table
*/
void print_times_table(int n)
{
int i, j, k;

if (n >= 0 && n <= 15)
{
for (i = 0; i <= n; i++)
{
for (j = 0; j <= n; j++)
{
k = j * i;
if (j == 0)
{
_putchar(k + '0');
} else if (k < 10 && j != 0)
{
_putchar(',');
_putchar(' ');
_putchar(' ');
_putchar(' ');
_putchar(k + '0');
} else if (k >= 10 && k < 100)
{
_putchar(',');
_putchar(' ');
_putchar(' ');
_putchar((k / 10) + '0');
_putchar((k % 10) + '0');
} else if (k >= 100)
{
_putchar(',');
_putchar(' ');
_putchar((k / 100) + '0');
_putchar(((k / 10) % 10) + '0');
_putchar((k % 10) + '0');
}
}
_putchar('\n');
}
}
}

0 comments on commit d19c146

Please sign in to comment.