Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following C# code?
static void Main(string[] args)
{
long x;
x = Convert.ToInt32(Console.ReadLine());
do
{
Console.WriteLine(x % 10);
}while ((x = x / 10) != 0);
Console.ReadLine();
}
enter x = 1234.

What will be the output of the following C# code?
static void Main(string[] args)
{
long x;
x = Convert.ToInt32(Console.ReadLine());
do
{
Console.WriteLine(x % 10);
}while ((x = x / 10) != 0);
Console.ReadLine();
}
enter x = 1234.
a) number of digits present in x
b) prints ‘1’
c) prints reverse of x
d) prints sum of digits of ‘x’

Answer: c
Explanation: Reverse of digits using while loop statements.
Output: 4321.

Join The Discussion