Code Monkey home page Code Monkey logo

recursive-function's Introduction

Recursive-function

Aim:

To write a C# program to reverse a number using recursive function.

Algorithm:

Step 1 :

Import the 'System' namespace to use the classes present in the 'System' namespace.

Step 2 :

Declare a function to recursive reverse the digits in the number .

Step 3 :

In the recursive function , find the remainder of the digit.If the remainder is equal to 0 then return 0 else add the remainder obtained and then call the function 'fun' again untill it turns 0.

Step 4 :

Declare the Main function and get the user input .

Step 5 :

Call the function and execute the program.

Program:

using System;
namespace Program
{
    class Program
    {
        int rem = 0, rev = 0;
        public int fun(int number)
        {
            rem = number % 10;
            if (rem == 0)
            {
                return rev;
            }
            else
            {
                rev = rev * 10 + rem;
                return fun(number / 10);
            }
        }
        static void Main(string[] args)
        {
            int n;
        
            Console.WriteLine("Enter a Number: ");
            n = Convert.ToInt32(Console.ReadLine());

            Program reverse= new Program();
            Console.WriteLine("Reverse Number : {0} ",reverse.fun(n));
            
        }
    }
}

Output:

op

Result:

A C# program to reverse a number using recursive function is written and executed.

recursive-function's People

Contributors

archanasharikalharinarayanan avatar sowmiya2003 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.