Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how do i store a three digit number seperatley for each digit?

+9 votes
asked May 18, 2025 by Archith Iyer (210 points)

3 Answers

0 votes
answered May 18, 2025 by Michal Schmidt (140 points)

A simple method is to use the modulo (%) operator and integer division. Here's how you can extract each digit from a number like 125:

  1. Get the last digit using modulo 10:
    125 % 10 = 5

  2. Remove the last digit by dividing by 10:
    125 / 10 = 12 (integer division)

  3. Get the next digit:
    12 % 10 = 2

  4. Remove the last digit again:
    12 / 10 = 1

Now you’ve extracted all three digits: 1, 2, and 5.
You can store them in variables, an array, or use them however you need.

0 votes
answered Jun 22, 2025 by Grid Technical (200 points)
number=125
list1=[]
num1=str(number)
for i in num1:
    list1.append(i)
list2=list(map(int,list1))
var1,var2,var3=list2[0],list2[1],list2[2]
print("Variable 1:",var1)
print("Variable 2:",var2)
print("Variable 3:",var3)
0 votes
answered Jun 26, 2025 by Monisha D (140 points)
Simple suppose the number is 1234 use Modulo operator for it

Code :-

int main()

{

int a = 1234;

printf("%d\n%d\n%d\n%d",a%10,a/10%10,a/100%10,a/1000%10);

return 0;

}

You will get the output as

4

3

2

1
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...