-
Notifications
You must be signed in to change notification settings - Fork 0
/
100-times_table.c
55 lines (48 loc) · 874 Bytes
/
100-times_table.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
49
50
51
52
53
54
55
/*
* File: 100-times_table.c
*
* Author: Stanley O. Ajanaku
*/
#include "main.h"
/**
* print_times_table - Prints the times table of the input,
* starting with 0.
*
* @n: The value of the table to be printed.
*/
void print_times_table(int n)
{
int parent, child, result;
if (n >= 0 && n <= 15)
{
for (parent = 0; parent <= n; parent++)
{
_putchar('0');
for (child = 1; child <= n; child++)
{
_putchar(',');
_putchar(' ');
result = parent * child;
if (result <= 99)
{
_putchar(' ');
}
if (result <= 9)
{
_putchar(' ');
}
if (result >= 100)
{
_putchar((result / 100) + '0');
_putchar(((result / 10)) % 10 + '0');
}
else if (result <= 99 && result >= 10)
{
_putchar((result / 10) + '0');
}
_putchar((result % 10) + '0');
}
_putchar('\n');
}
}
}