Code Monkey home page Code Monkey logo

recursive-function's Introduction

EX-7 Recursive-function

Date:

Aim:

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

Algorithm:

Step 1:

Create a class called reverse.

Step 2:

Create a recursive function named RevNum to reverse the number

Step 3:

In the function find reminder of the number and multiply it by 10 and add the reverse number.

Step 4:

Recusively call this function to get the reversed number.

Step 5:

Create a Main function

Step 6:

Get input from the user for the number to be reversed.

Step 7:

Call the function RevNum

Step 8:

End of the program.

Program:

Developed By : SWATHIKA G
Register Number : 212221230113
using System;

class Program
{
    static int reverse(int num, int rev)
    {
        if (num == 0)
        {
            return rev;
        }
        else
        {
            rev = rev * 10 + num % 10;
            return reverse(num / 10, rev);
        }
    }
    static void Main(string[] args)
    {
        int num, rev = 0;
        Console.Write("Enter a number: ");
        num = int.Parse(Console.ReadLine());

        rev = reverse(num, rev);
        Console.WriteLine("Reverse of {0} is {1}", num, rev);
    }
}

Output:

output

Result:

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

recursive-function's People

Contributors

swathika28 avatar archanasharikalharinarayanan 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.