How to seperate the digit and store it in different variables | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

How to seperate the digit and store it in different variables

Like Integer is 12345 P=1 Q=2 R=3......etc

12th Jun 2019, 2:35 PM
MOUSE WIRE
MOUSE WIRE - avatar
3 Réponses
+ 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; }
12th Jun 2019, 5:43 PM
Jackson O’Donnell
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
12th Jun 2019, 2:46 PM
✳AsterisK✳
✳AsterisK✳ - avatar
0
Thank u
12th Jun 2019, 5:45 PM
MOUSE WIRE
MOUSE WIRE - avatar