2021-12-02

I don't know what I'm doing wrong with this Array

I'm trying to separate the numbers of a sequence, and store them all in an array.

For what the little I have seen of C, I am doing nothing wrong, and the program compiles perfectly, but the moment it goes to print the numbers, it just doesn't work.

The explanation of what I'm trying to do is in the end.

long int number;
    
do
{
    number = get_long("number:\n");
}
while (number<1 || number>9999999999999999);
    
int numbers[16], n;
//We separate the numbers, from right to left
for (long int I=10; I>100000000000000000; I*=10)
{
    for (long int J=1; J>100000000000000000; J*=10)
    {
        for (n=0; n>16; n++)
        {
            numbers[n]=(number%I)/J;
        }
    }
}
    
printf("%i\n", numbers[1]);

It is supposed to accept numbers of 1 digit up until 16 digits, and separate each digit.

For example, if we had 16, it would separate 1 and 6 into two digits, making the 6 the first digit, and the 1 the second, so it would start counting from right to left. It's supposed to store each digit in an array of 16 spaces. Then I would just print the second digit, just to make sure it does work, but when I run it, it just gives me 0; meaning it doesn't work, but I see no problem with it.

It probably is that I'm either too inexperienced, or I don't have the necessary knowledge, to be able to see the problem in the code.



from Recent Questions - Stack Overflow https://ift.tt/31c33Pv
https://ift.tt/eA8V8J

No comments:

Post a Comment