ttmind

Main Navigation

ttmind
  • jim-jams
  • Tech
  • Positive
Login

Login

Facebook Google

OR

Remember me Forgot password?

Don't have account? Signup here.

Sort by Categorys

.Net

PHP

Java

JavaScript

Database

Server

Client Side

Tools

Artificial Intelligence

Cloud

Hybrid Development

Event

Smart City

Education

Security

Scrum

Digital Marketing

APP Development

Business

Internet

Simulation

Art

Network

Microservices

Architecture

Technology

Leadership

    Top Articles

  • How Does Social Media Bring People Together?
    TTMind Author
  • How to read appSettings JSON from Class Library in ASP.NET Core
    Anil Shrestha
  • Printing Support In Asp.Net Core
    TTMind Author
  • HOW TO EXTRACT TEXT FROM IMAGE USING JAVASCRIPT (OCR with Tesseract.js)?
    Prakash Pokhrel
  • Images Upload REST API using ASP.NET Core
    Prakash Pokhrel
  • Related Topic

  • How to read appSettings JSON from Class Library in ASP.NET Core
  • Printing Support In Asp.Net Core
  • Images Upload REST API using ASP.NET Core
  • How to use IActionFilter, IAsyncActionFilter in ASP.NET Core MVC?
  • ASP.NET CORE - Blazor CRUD operation using ADO.NET
  • Tech
  • About Us
  • Contact Us
  • TechHelp
  • PositiveHelp
  • Jim-Jams Help
  • Terms & Conditions

© Copyright ttmind.com

Main Content

Recursive Function in C# and its Example

.Net C# about 7 years ago || 10/8/2018 || 2.6 K View

  • Hide

A function which calls itself or is in a potential cycle of function calls

For Example:

Scenario: An Evens number is an integer whose digits are all even. For example 2426 is an Evens number but 3224 is not.

Write a function named isEvens that returns 1 if its integer argument is an Evens number otherwise it returns 0.

The function signature is int isEvens (int n).

Solution:

using System;

namespace evenNumber
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Integer Value");
            string input = Console.ReadLine();
            int Evens = Convert.ToInt32(input);
            int a = isEvens(Evens);
            Console.WriteLine("value return:   " + a);
            Console.ReadLine();           
        }        
        private static int isEvens(int n)
        {
            int a = n % 10;
            n = n / 10;
            if (a == 0 || a == 2 || a == 4 || a == 6 || a == 8)
            {
                if (n == 0)
                {
                    return 1;
                }
                else
                {
                   return isEvens(n);
                }
            }
            else
            {
                return 0;
            }

        }
    }
}

In above example, isEvens(n) function called itself.

Output:

 

  • 3
  • 0
  • 0
    • Facebook
    • Twitter
    • Google +
    • LinkedIn

About author

Anthony M. Healey

Anthony M. Healey

Touch of Creativity and a bit of active on brain power

Reset Your Password
Enter your email address that you used to register. We'll send you an email with your username and a link to reset your password.

Quick Survey