Skip to content

Commit 59def8a

Browse files
committed
added: 5-more_numbers.c
1 parent b32d9d0 commit 59def8a

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "main.h"
2+
3+
/**
4+
* printDigits - print numbers more than 2 digits.
5+
*
6+
* @n: number to be processed.
7+
*
8+
* Return: Nothing.
9+
*/
10+
void printDigits(int n)
11+
{
12+
int singleDigit;
13+
int base = 10;
14+
15+
while (n >= base)
16+
{
17+
base = base * 10;
18+
}
19+
while (base != 1)
20+
{
21+
singleDigit = (n % base) / (base / 10);
22+
_putchar(singleDigit + '0');
23+
base = base / 10;
24+
}
25+
}
26+
27+
/**
28+
* more_numbers - prints 10 times the numbers,
29+
* from 0 to 14, followed by a new line.
30+
*
31+
* Return: Nothing.
32+
*/
33+
void more_numbers(void)
34+
{
35+
int line;
36+
int counter;
37+
38+
for (line = 0; line <= 9; line++)
39+
{
40+
for (counter = 0; counter <= 14; counter++)
41+
{
42+
printDigits(counter);
43+
}
44+
_putchar('\n');
45+
}
46+
}

0x04-more_functions_nested_loops/main.h

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ int _isdigit(int);
44
int mul(int, int);
55
void print_numbers(void);
66
void print_most_numbers(void);
7+
void more_numbers(void);

0 commit comments

Comments
 (0)