#include <stdio.h>
void print_integer_as_string(int num) {
// Your logic here
char buffer[12]; // Enough for -2147483648 + null terminator
int i = 0;
// Handle zero explicitly
if (num == 0) {
printf("0\n");
return;
}
// Handle negative numbers
if (num < 0) {
putchar('-');
putchar(' ');
num = -num;
}
// Extract digits in reverse
while (num > 0) {
buffer[i++] = '0' + (num % 10);
num /= 10;
}
// Print digits in correct order with spaces
while (i--) {
putchar(buffer[i]);
if (i > 0) putchar(' ');
}
putchar('\n');
}
int main() {
int num;
scanf("%d", &num);
print_integer_as_string(num);
return 0;
}Handle Zero Case
num == 0, print '0' and returnHandle Negative Numbers
num < 0:'-' followed by a spacenum to positive using num = -numExtract Digits in Reverse
char buffer[12]) to store digitsdigit = num % 10'0' + digitnum = num / 10Print Digits in Correct Order
Input
123
Expected Output
1 2 3