I made a program that splits a number into numbers that, when added, give the first number. For example, 1234 should be split into 1000, 200, 30, and 4.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main ()
{
int i, num1, num2;
char tmp[6]; // the number will be stored here as string
int num3 = 12345; //the number
sprintf(tmp, "%d", num3); //convert to string
for(i = 0; i < strlen(tmp); i++) //check every digit
{
num1 = pow(10, strlen(tmp) - 1 - i); //every number will be multiplied by 10
//to the power of number of digits - 1 - counter
num2 = tmp[i] - '0'; //convert character to int
printf("%d\n", num1*num2); //print the number
}
return 0;
}
This is the output:
9999
2000
297
40
5
As you can see this is not correct, why?