#include <stdio.h> void print_integer_as_string(int num) { if (num == 0) { printf("0"); return; } char res[20]; int i = 0; bool negative = false; if (num < 0) { negative = true; num = -num; } while (num > 0) { res[i++] = (num % 10) + '0'; num /= 10; } if (negative) { res[i++] = '-'; } for (int j = i - 1; j >= 0; j--) { printf("%c ", res[j]); } } int main() { int num; scanf("%d", &num); print_integer_as_string(num); return 0; }
Test Cases
Test Results
Input
123
Expected Output
1 2 3