How to figure out digit place in given number
Example
Input
Input number: 6294Output
digit place 1: 6
digit place 2: 2
digit place 3: 9
digit place 2: 4
What is logic to find digit place in number given number
How to figure out digit place in given number
Example
Input
Input number: 6294Output
digit place 1: 6
digit place 2: 2
digit place 3: 9
digit place 2: 4
What is logic to find digit place in number given number
I would use the logic commonly used to reverse the order or digits.
In example, the code to change "6294" to "4926".
But, I have never seen this exact problem.
If I wished to solve it without using the normal beginner way.
I would just use snprintf function.
Tim S.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson
The way to change "6294" to "4926" in simple beginner code;
Uses divide by 10 and modulus by 10. The % percent sign is the C modulus operator.
Tim S.
Last edited by stahta01; 01-27-2018 at 01:22 PM.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson
I can do it but I am looking another way
Reverse number is = 4926Code:#include<stdio.h> int main (void) { unsigned int number = 6294; int reverse=0; while (number != 0) { reverse = reverse * 10; reverse = reverse + number % 10; number = number / 10; } printf("Reverse number is = %d \n", reverse); return 0; }
Do you know any another way like I was saying ?
How about this, just uses inter math.
If the division return zero then you know the number does not take up that place holder
6294/1000=6
6294-6*1000= 294 subtract last result to get next number
294/100=2
294-200=94
94/10=9
94-90=4
4/1=4
4-4*1=0 your done !
Last edited by stahta01; 01-28-2018 at 02:40 AM.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson