0
How to seperate the digit and store it in different variables
Like Integer is 12345 P=1 Q=2 R=3......etc
3 Answers
+ 1
You need to either count the number of containers you need or dynamically allocate memory as you go. An easy way to count is to put the number in a temporary variable and divide by 10 (integer division) until the number reaches 0.
Then you can go ahead and mod by 10 to get a number, and divide by 10 to remove it. Keep doing this until the number reaches 0.
Idk how to embed code here so here goes:
int x = 12345;
int y =x;
int numnums = 0; //number of conainters
while(y >0){
y/=10;
numnums++;
}
int split[numnums];
y = x;
while(y > 0){
split[numnums-1] = (y%10);
Y/=10;
}
0
you need to count the total digit first t determine how many containers you need, and use the separation techniques to separate 3m and store each in the variable you want using switch or if else statement
0
Thank u