Need little information with Arrays

Thread Starter


Joined Jan 19, 2018

I have one question with C-Programming.

Assume there is one variable => int var1;

Value at var1 = 1234;

Now I want separate each bit of this var1 and store in an array[4].

So output should be.
array[0] = 1
array[1] = 2
array[2] = 3
array[3] = 4

Can somebody suggest some program steps to have output shown as above ??

Thanks in advance.


Joined Jun 4, 2014
array[3] = var1 % 10;
var1 /=10;
array[2] = var1 %10;
var1 /=10;
array[1] = var1 % 10;
var1 /=10;
array[0] = var1;


Joined Mar 31, 2012
Actually I am beginner in Programming world
Which usually describes people working on an early homework assignment in a beginning programming course.

But whether you are taking a course or doing it on your own, the same reality applies. The vast majority of the time you will learn a LOT better if YOU struggle with the concepts, put forth your best attempts, and then people here look them over and try to help YOU spot the problems and guide YOU toward finding the solution. It's certainly the more painful route (for both sides), no doubt. But if the goal is for YOU to learn something, that's the price of the ticket.