diff options
author | sinanmohd <pcmsinan@gmail.com> | 2022-06-15 12:09:19 +0530 |
---|---|---|
committer | sinanmohd <pcmsinan@gmail.com> | 2022-06-15 12:09:19 +0530 |
commit | fdd66ab773f88dcf31fc55b647d6d2de7f0647cf (patch) | |
tree | ef0b04868d1117fcf31db7d4225987c36ae5bc63 | |
parent | b9b7a4ef7ee071edd7a07788a62f6d81871dfb19 (diff) |
add 4.12.c
-rw-r--r-- | 4.12.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -0,0 +1,38 @@ +#include <stdio.h> + +#define MAXLEN 30 + +char* itoa(char str[], int num); + +int +main(void) +{ + char str[MAXLEN]; + int num; + + num = -69420; + + printf("%d\n", num); + printf("%s\n", itoa(str, num)); + + return 0; +} + +char* +itoa(char str[], int num) +{ + static int i = 0; + + if (num < 0) { + num = -num; + str[i++] = '-'; + } + + if (num/10) + itoa(str, num/10); + + str[i++] = '0' + (num % 10); + str[i] = '\0'; + + return str; +} |