I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class csharpExercise
{
static void Main(string[] args)
{
int num, last;
// Reading number
Console.Write("Enter any number: ");
num = Convert.ToInt32(Console.ReadLine());
last = num % 10;
Console.WriteLine("The last digit of entered number: "+ last);
while (num >= 10)
{
num = num / 10;
}
Console.WriteLine("The first digit of entered number: "+ num);
Console.ReadLine();
}
}
I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..
Result:
Enter any number: 123456
The last digit of entered number: 6
The first digit of entered number: 1
need an explanation for this answer? contact us directly to get an explanation for this answer