using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace prime_number
{
class findPrime
{
int[] num = new int[5]; /*Creating array for numbers*/
int i, j;
bool isprime,noprime = true;
public findPrime()
{
Console.WriteLine("Please enter 5 numbers: ");
for(i = 0; i < 5; i++)
num[i] = Int16.Parse(Console.ReadLine()); /* add Numbers to the Array*/
for(i = 0; i < 5; i++)
{
isprime = true; /* initialize Current number as prime Number is "true"*/
for (j = 2; j <= (num[i] / 2); j++)
/* for Diving numbers for Remainder "0" from 2 to the half of the Number*/
{
if (num[i] % j == 0)
{
isprime = false;
/*if Remainder "0" Found set Current Number as prime is "false" and break the loop */
break;
}
}
if (isprime) /*if no Remainder "0" Display current Number as Prime Number*/
{
noprime = false;
Console.WriteLine(num[i] + " is a Prime Number");
}
}
if (noprime)
Console.WriteLine("There is no a Prime number in the list");
}
}
class Program
{
static void Main(string[] args)
{
findPrime pn = new findPrime(); /* Create object of the class */
Console.ReadLine();
}
}
}
gud..
ReplyDeleteToo complicated. Can be done in a much easy manner.
ReplyDelete