int main()
{
int n, k;
int i = 10;
int j = 0;
int numray[11];
numray[0] = 0;
printf("ENTER A NUMBER...\n");
scanf("%d", &n);
printf("ENTER THE KTH DIGIT FROM THE RIGHT...\n");
scanf("%d", &k);
while (n / i != 0)
{
n %= i;
i *= 10;
j += 1;
numray[j] = n;
if (j == k)
{
printf("Your kth integer is %d \n", numray[j]);
}
}
}```
The above code does not display a number for any k which is not 1 /:
#confused
15 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
perhaps you shouldnt multiply i by 10 in the loop
in theory, you should do
n last_dig
829 -> 9
82 -> 2
8 -> 8
done
you are doing:
n last_dig
829 -> 9
9 -> done
perhaps think about how n is modified to go from 829 to 82
!debug
!debugger
Have you tried stepping through your code line by line in a debugger?
If you don't know how to use a debugger or don't have one set up, we highly recommend taking the time to do so.
Debuggers are immensely helpful tools for figuring out where problems emerge in code and especially when you're first learning it can help you build intuition and understanding for reasoning through code.
Resources:
- Getting started with debugging in Visual Studio
- Getting started with debugging in vscode on windows
- Getting started with debugging in vscode on linux
- If your IDE isn't listed here, you can find a guide for your IDE online
debuggers are cool things to help see what really is happenning, step by step
you can even use paper and pencil, that's a totally acceptable debugger team for a problem like this
like making a table of variables, how they change each step
oh, why not
okay, will try that
ive been using online compilers for a while now lol