-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnumbers.c
128 lines (106 loc) · 1.8 KB
/
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "main.h"
/**
* print_number - prints an integer
*
* @n: integer to be printed
*/
void print_number(int n)
{
unsigned int new_number = 0;
if (n == -2147483648)
{
new_number = n;
_putchar('-');
new_number = -new_number;
if (new_number / 10)
print_number(new_number / 10);
_putchar('0' + (new_number % 10));
return;
}
else if (n < 0)
{
_putchar('-');
n = -n;
}
if (n / 10)
print_number(n / 10);
_putchar('0' + (n % 10));
}
/**
* count_number - Counts a number
*
* @n: integer to be printed
*
* Return: The size of the number less 1.
*/
int count_number(int n)
{
int counter = 0;
if (n == 0)
return (0);
if (n < 0)
{
n *= -1;
counter++;
}
while (n != 0)
{
n /= 10;
counter++;
}
return (counter - 1);
}
/**
* rot13 - funcion that encodes a string using rot13
*
* @str: string to be convert
*
* Return: pointer direction
*/
char *rot13(char *str)
{
int i;
for (i = 0; (*(str + i) != '\0'); i++)
{
while ((str[i] >= 'a' && str[i] <= 'z') || (str[i] >= 'A' && str[i] <= 'Z'))
{
if ((str[i] >= 'a' && str[i] <= 'm') || (str[i] >= 'A' && str[i] <= 'M'))
{
str[i] = str[i] + 13;
break;
}
str[i] = str[i] - 13;
break;
}
}
return (str);
}
/**
* print_num_binary - function that print number in binary
*
* @n: number to convert
*
* @counter: Counter of the number of binary digits that are printed
*/
void print_num_binary(unsigned int n, unsigned int *counter)
{
if (n != 2 && n != 3)
print_num_binary(n / 2, counter);
else
_putchar((n / 2) + '0');
_putchar((n % 2) + '0');
*counter += 1;
}
/**
* print_rev - function that prints a string in reverse
*
* @s : variable to pointer
*/
void print_rev(char *s)
{
int i = 0, j = 0;
while (*(s + i) != '\0')
i++;
for (j = i - 1; j >= 0; j--)
_putchar(s[j]);
}