Find First and Last Digit of Number in C#

Hi Programmers, Welcome to Ozanecare. This Article i am
going to Write the program to display first and last
digit of any enter number using c# language.Let’s see the
below program.

Code Explanation : if you run/debug the program then control
first go to main method after that it comes inside main
method. there i have taken integer variable users enter
any positive number for example 678942. then n % 10 so 678942 % 10 = 2. the mod operator return last digit of number. D2 = 2.For first digit. n value move to D1. D1 >= 10 or 678942 >= 10 while condition true then n/10 678942 / 10 then value returns 67894, 6789,678, 67,6. 6 >= 10 then Condition False. D1=6 so Last digit equal to 6.

Happy Coding…Thanks.

Post Author: adama