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

Find prime number between two range.

.Net C# about 7 years ago || 5/26/2019 || 1.6 K View

  • Hide

 Write a function named prime count with a signature in int PrimeCount(int start, int end); the function print the prime number from the given range.

Recall the prime is an integer greater than 1whose only integer factor is one or itself.

if start is And end is  reason

10

30 The prime between 10 to 30 are 11 ,13 ,17 ,19, 23 ,29.
11 29 The prime between 10 to 30 are 11 ,13 ,17 ,19, 23 ,29.
20 22 20,21,22 are all non-prime
1 1 by definition 1 is not prime
5 5 5 is prime
6 2 starting number must less than or equal to the end 
-10 6 Prime is greater than 1,2,3,5
using System;
public class PrimeCount
{
    public int Result(int start, int end)
    {

        int a = start, b = end;
        int i = 1, j;


        if (a > 0 && b > 0)
        {

            if (a < b)
            {

                if (a >1 && b > 1)
                {

                    for (j = a; j <= b; j++)
                    {

                        int c = 0;

                        for (i = 1; i <= b; i++)
                        {
                            if (j % i == 0)
                            {

                                c++;
                            }
                        }
                        if (c == 2)
                        {
                            Console.WriteLine(j + " "+ "It a prime");

                        }

                        else
                        {
                            Console.WriteLine(j + " " + "It is not prime");
                        }

                    }
                }
                else
                {
                    Console.WriteLine("by Defination it is not prime" + a, b);
                }
            }
            else
            {
                Console.WriteLine("Starting number must be smaller than ending number" + a, b);
            }

        }
        else
        {
            Console.WriteLine("please enter greater than 0");
        }
        return 1;

    }
}

namespace AssignmentFirst
{
    class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Enter the starting number");
            int start = Convert.ToInt16(Console.ReadLine());
            Console.WriteLine("Enter the Ending number");
            int end = Convert.ToInt16(Console.ReadLine());
            PrimeCount objCount = new PrimeCount();
            objCount.Result(start, end);
            Console.ReadLine();
        }
    }
   
}


  • 2
  • 0
  • 0
    • Facebook
    • Twitter
    • Google +
    • LinkedIn

About author

Anita Shrestha

Anita Shrestha

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