All submissions

Convert Integer to String

Code

#include <stdio.h>

void print_integer_as_string(int num) {
    char str[20] = {0};
    int index = 19;
    char is_neg = num < 0;
    if (is_neg)
    {
        printf("- ");
        num *= -1;
    }
    do
    {
        str[index] = (num % 10) + '0';
        num /= 10;
        index--;
    }while (num);
    while (str[++index])
        printf("%c ", str[index]);
}

int main() {
    int num;
    scanf("%d", &num);
    print_integer_as_string(num);
    return 0;
}

Solving Approach

 

 

 

Loading...

Input

123

Expected Output

1 2 3