File tree 2 files changed +63
-0
lines changed
0x02-functions_nested_loops
2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include "main.h"
2
+
3
+ /**
4
+ * checkDigits - check num of digits.
5
+ *
6
+ * @n: number.
7
+ *
8
+ * Return: return nothing.
9
+ */
10
+ void checkDigits (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
+ /**
29
+ * print_to_98 - prints all natural number from `n` to 98,
30
+ * followed by a new line.
31
+ *
32
+ * @n: the start number.
33
+ *
34
+ * Return: return nothing.
35
+ */
36
+ void print_to_98 (int n )
37
+ {
38
+ while (n != 98 )
39
+ {
40
+ if (n >= 0 && n <= 98 )
41
+ {
42
+ checkDigits (n );
43
+ n ++ ;
44
+ }
45
+ else if (n < 0 )
46
+ {
47
+ _putchar ('-' );
48
+ checkDigits (n * -1 );
49
+ n ++ ;
50
+ }
51
+ else
52
+ {
53
+ checkDigits (n );
54
+ n -- ;
55
+ }
56
+
57
+ _putchar (',' );
58
+ _putchar (' ' );
59
+ }
60
+ checkDigits (98 );
61
+ _putchar ('\n' );
62
+ }
Original file line number Diff line number Diff line change @@ -9,3 +9,4 @@ int print_last_digit(int);
9
9
void jack_bauer (void );
10
10
void times_table (void );
11
11
int add (int , int );
12
+ void print_to_98 (int );
You can’t perform that action at this time.
0 commit comments