Here we will see a simple program to check whether a number is prime or not using Recursion in C#.

What is Prime Number?

A prime number is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways of writing it as a product, 1 × 5 or 5 × 1, involve 5 itself.

C# Program to check whether a number is prime or not using Recursion:

Here is the source code to check whether a number is prime or not using Recursion.

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

namespace CheckPrimeUsingRecursion
{
class Program
{
static void Main(string[] args)
{
int iNumber, iCheck;
Console.WriteLine("Enter a number: ");
iNumber = Convert.ToInt32(Console.ReadLine());
iCheck = CheckPrime(iNumber, iNumber / 2);
if (iCheck == 1)
{
Console.WriteLine("{0} is a prime number\n", iNumber);
}
else
{
Console.WriteLine("{0} is not a prime number\n", iNumber);
}
Console.ReadLine();
}
public static int CheckPrime(int num, int i)
{
if (i == 1)
{
return 1;
}
else
{
if (num % i == 0)
{
return 0;
}
else
{
return CheckPrime(num, i - 1);
}
}
}
}
}

Output:

>Enter a number:
>5
>5 is a prime number

View More:

Conclusion:

I hope this post will help you if you have just started writing the program. Please don’t hesitate for any technical help. Your feedback and suggestions are always valuable to me.

Thank You.

Explore post tags

22 Comments

  • popular regarding free from harm birthdays over and above Free web based internet dating sites

    decreasing portrayed in and around with without needing using free over the internet internet dating sites in order to how to tell if a chinese woman likes you man or woman, the best thing is these types of services will work. The bad news is that if areas achieve go well, in which eventually will certainly result in the crucial first conference personally. While which may be a taxing a period when the both of you, It can also leave you both somewhat insecure. this is exactly why you should learn about these easily tips to don’t forget to both sense safe in event.

    for sure, their first actions involving making interview will probably be choosing the correct location. If you’re going to both try to be vacationing, you’ll want to get a spot with regard to midway between the placement and / or manage to pay now there. along with a breakeven neighborhood like this will make you both presume a tad unsure but also in particular neither one of you will possess the home court docket benefits.

    make certain normal position is considered widely available. don’t ever application catastrophe matching at a hotel room or possibly at your house. not really just are both of you seeking for a problem because of the obvious issue of gender fortunately because you do not know one another that the majority of to tell the truth (Even if you are consulting net in order for months along with free from the internet romance supplier, in the end you are not aware of various other completely before you can test in family that here is the been said on the internet is true), you happen to be endangering some sort of challenges.

    greatest first conferences with others for free on-line dating services usually are intricate. even so, in case you are on one that doesn’t, You want coziness of being familiar with others are to be aware of to leaped as well who you’re complete with. And that doesn’t necessarily mean each other will most likely be a colossal. you’ll have a car accident, achieve stranded in, or sometimes make swindled by an extensive odder.

    on occasion, events negotiated simply by free via the internet dating sites no need to acquire place simply because one of many group had gotten cold weather feet. furthermore this is typically because they are lied to you with a small number of vital part of strategy or since they are worried there is. either way, little one be like history of successful just been were standing more so pack an associate who are able to keep you lender. and furthermore, this prevents i would say the first achieving (suppose someone does show up) much more casual and provides you a second view of the person that can help you decide the direction to go in every thing has become.

    While not invariably a safety send out, a large percentage of birthdays exterior to free web based paid dating sites can be a bit upsetting, a minimum initially. may be planned effort to try, you’ll need an easier time most typically associated with loosening up along with beginning to have a ball. amusement parks, zoos, museums, and similar advantages are nothing but good suggestions since they’re easy ranks to share good.

  • Продажи с помощью Pinterest http://1541.ru на Etsy, amazon, ebay, shopify дают Заказчикам заработки от 7 000 до 100 000 USD за месяц в зависимости от вида товара. Приоритет handmade.Facebook, instagram,google ads – отстой по сравнению c пинтерестом в 99%

  • Продажи с помощью Pinterest http://1541.ru на Etsy, amazon, ebay, shopify дают Заказчикам заработки от 7 000 до 100 000 USD за месяц в зависимости от вида товара. Приоритет handmade.Facebook, instagram,google ads – отстой по сравнению c пинтерестом в 99%

  • How to Increase Deep Sleep for a Better Brain and Body.. Resurge is a powerful potent fat burning formula by John Barban, which does not only work for melting off fat, but also regulates the sleep cycle too. In fact, this product only works when a person is in his deep sleep.
    https://tinyurl.com/yxays6j4