-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3-mul.c
More file actions
48 lines (41 loc) 路 778 Bytes
/
Copy path3-mul.c
File metadata and controls
48 lines (41 loc) 路 778 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
#include "main.h"
/**
* _atoi - Converts a string to an integer.
* @s: The string to be converted.
* Return: The integer value of the converted string.
*/
int _atoi(char *s)
{
int sign = 1;
unsigned int num = 0;
do {
if (*s == '-')
sign *= -1;
else if (*s >= '0' && *s <= '9')
num = (num * 10) + (*s - '0');
else if (num > 0)
break;
} while (*s++);
return (num * sign);
}
/**
* main - multiplies two numbers
* @argc: number of arguments
* @argv: array of arguments
*
* Return: 0 (Success), 1 (Error)
*/
int main(int argc, char *argv[])
{
int result, num1, num2;
if (argc < 3 || argc > 3)
{
printf("Error\n");
return (1);
}
num1 = _atoi(argv[1]);
num2 = _atoi(argv[2]);
result = num1 * num2;
printf("%d\n", result);
return (0);
}