-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnumbers.c
More file actions
executable file
·51 lines (50 loc) · 788 Bytes
/
numbers.c
File metadata and controls
executable file
·51 lines (50 loc) · 788 Bytes
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
#include "holberton.h"
/**
* printNum - Prints a number.
*
* @n: Input number.
*
* Return: Number of bytes printed.
*/
int printNum(va_list n)
{
unsigned int i, abs, abs1, digit, digit1, div = 1, num, last;
int number, len = 0;
char p;
number = va_arg(n, int);
if (number < 0)
{
write(1, "-", 1);
abs = -1 * number;
abs1 = -1 * number;
len++;
}
else
{
abs = number;
abs1 = number;
}
for (digit1 = 1; abs1 / 10 > 0; digit1++)
abs1 = abs1 / 10;
for (i = digit1 - 1; i > 0; i--)
div = div * 10;
for (digit = digit1; digit >= 1; digit--)
{
num = abs / div;
if (num >= 10)
{
last = num % 10;
p = last + '0';
write(1, &p, 1);
len++;
}
else
{
p = num + '0';
write(1, &p, 1);
len++;
}
div = div / 10;
}
return (len);
}