using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program
{
class Program
{
static void Main(string[] args)
{
int num, reverse = 0;
Console.WriteLine("Enter a Number : ");
num = int.Parse(Console.ReadLine());
while (num != 0)
{
reverse = reverse * 10;
reverse = reverse + num % 10;
num = num / 10;
}
Console.WriteLine("Reverse of Entered Number is : "+reverse);
}
}
}
I can grasp at the concept of the previous values of reverse accumulating during the iterations of the loop but why doesnt WriteLine() also output the string "Reverse of Entered Number is: " 3 times? I know it somewhat happens if I enter it in the loop body but the reverse output is still:
blah blah blah: 3 // I understand this
" " : 32 // I thought this was going to output 2
" " : 321 // while this outputs 1
Why is the "+ reverse" bit the only command executed? and not the whole line?
im sorry if this is a very basic or dumb question, its really bothering me had to create a SO account for it.