Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

asdasd

using System;

namespace Tanulas
{
    class IsPrime
    {
        static void Main()
        {
            TestOperation();
        }
        static int UserInput()
        {
            Console.Write("Kérek egy számot: ");
            int input = int.Parse(Console.ReadLine());
            return input;
        }
        static void UserOperation()
        {
            var input = UserInput();
            Prime(input);
        }
        static void TestOperation()
        {
            var r = new Random();
            for (int i = 0; i < 10; i++)
            {
                var input = r.Next(1, 100);
                Prime(input);
            } 
        }
        static bool ModCounter(int input)
        {
            int mods = 0;
            int cnt;

            for (int i = 1; i <= input; i++)
            {
                cnt = input % i;
                if (cnt == 0)
                {
                    mods++;
                }
            }

            if (mods == 2)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        static void Prime(int input)
        {
            if (ModCounter(input) == true)
            {
                Console.WriteLine("!!! " + input + " PRÍMSZÁM !!!");
            }
            else
            {
                Console.WriteLine(input + " nem prímszám!");
            }
        }

    }
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.