summaryrefslogtreecommitdiffstats
path: root/3/4.c
diff options
context:
space:
mode:
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 6bcc1bb..90a970a 100644
--- a/3/4.c
+++ b/3/4.c
@@ -19,11 +19,12 @@ int main(int argc, char *argv[]) {
}
void itoa(int n, char s[]) {
- int i;
+ int i, sign;
i = 0;
+ sign = n < 0;
- if (n >= 0) {
+ if (!sign) {
do {
s[i++] = n % 10 + '0';
} while ((n /= 10) > 0);
@@ -36,7 +37,7 @@ void itoa(int n, char s[]) {
} while ((n /= 10) <= -1);
}
- if (n < 0)
+ if (sign)
s[i++] = '-';
s[i] = 0;