- Joined
- Oct 16, 2023

- Messages
- 1

- Reaction score
- 0

int get_number_of_digits(int x){

int j = 1, c = 1;

while (x / j >= 10) {

j *= 10;

c += 1;

}

return c;

}

void get_digits(int x, int T[], int size) {

int j = 1, v = x;

int i;

for (i = 0; i < size - 1; i++) {

T

*= v / j;*

v = v % j;

j /= 10;

}

T[size - 1] = v;

}

int main() {

int x;

printf("Enter a number : ");

scanf("%d",&x);

const int n = get_number_of_digits(x);

int *digits_stocker = (int *)malloc(n * sizeof(int));

get_digits(x, digits_stocker, n);

int k;

for (k = 0; k < n; k++) {

printf("T = %d\t", digits_stocker[k]);

}

free(digits_stocker);

return 0;

}

v = v % j;

j /= 10;

}

T[size - 1] = v;

}

int main() {

int x;

printf("Enter a number : ");

scanf("%d",&x);

const int n = get_number_of_digits(x);

int *digits_stocker = (int *)malloc(n * sizeof(int));

get_digits(x, digits_stocker, n);

int k;

for (k = 0; k < n; k++) {

printf("T = %d\t", digits_stocker[k]);

}

free(digits_stocker);

return 0;

}