-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction_numbers.c
73 lines (69 loc) · 952 Bytes
/
function_numbers.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include "holberton.h"
/**
* print_i - print an integer and decimal
* @_print: list of arguments
* Return: i - len
*/
int print_i(va_list _print)
{
int n, aux, i;
int count = 0;
char arg;
n = va_arg(_print, int);
if (n < 0)
{
aux = -n;
write(1, "-", 1);
count++;
}
else
aux = n;
for (i = 1; i <= cifras(aux); i++)
{
arg = ((aux / (_pow(10, cifras(aux) - i))) % 10) + 48;
write(1, &arg, 1);
count++;
}
return (count);
}
/**
* cifras - numero de cifras
* @n: number
* Return: count
*/
int cifras(int n)
{
int count = 1;
int control = 10;
if (n < 0)
{
n = -n;
}
while (control <= n)
{
count++;
control = control * 10;
}
return (count);
}
/**
* _pow - potentiation
* @x: num x
* @y: num y
* Return: function
*/
int _pow(int x, int y)
{
if (y < 0)
{
return (-1);
}
else if (y == 0)
{
return (1);
}
return (x * _pow(x, y - 1));
}