Sunday 19 February 2017

reverse number program in c# using while loop

frequently asking logical program in interviews for dotnet fresher

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication84
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, rev = 0, rem;
            Console.WriteLine("enter the no:");
            n = int.Parse(Console.ReadLine());
            while (n != 0)
            {
                rem = n % 10;
                rev = (rev * 10) + rem;
                n = n / 10;
            }
            Console.WriteLine("the reverse no is :{0}", rev);
            Console.ReadLine();
        }
    }
}

output: Screen Shot





No comments:

Post a Comment