aboutsummaryrefslogtreecommitdiff
path: root/3.4.c
diff options
context:
space:
mode:
authorsinanmohd <pcmsinan@gmail.com>2022-06-04 12:18:08 +0530
committersinanmohd <pcmsinan@gmail.com>2022-06-04 12:18:08 +0530
commit00af3bb6a98925c1b997f3b077615627e31ba24c (patch)
tree3581c55e65488596a2b3863face1aabeef8a28c1 /3.4.c
parentc24973af02bc33f2f5f25d37e22ca91da5de3c47 (diff)
fix for most -ve int
Diffstat (limited to '3.4.c')
-rw-r--r--3.4.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/3.4.c b/3.4.c
index 51386c6..d4a1c9a 100644
--- a/3.4.c
+++ b/3.4.c
@@ -8,7 +8,7 @@ char* itoa(int n, char str[]);
int
main(void)
{
- int n = -2147483648;
+ int n = 2147483647;
char str[MAXLEN];
printf("%d\n", n);
@@ -38,8 +38,8 @@ itoa(int n, char str[])
{
int sign, i;
- if ((sign = n) < 0)
- n = -n;
+ /* to include the most -ve int*/
+ n = ((sign = n) < 0) ? -(n+1) : n-1;
i = 0;
do {
@@ -49,6 +49,7 @@ itoa(int n, char str[])
if (sign <0)
str[i++] = '-';
+ str[0] += 1;
str[i] = '\0';
reverse(str);