Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
28
Task/Semiprime/C-sharp/semiprime.cs
Normal file
28
Task/Semiprime/C-sharp/semiprime.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
static void Main(string[] args)
|
||||
{
|
||||
//test some numbers
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
Console.WriteLine("{0}\t{1} ", i,isSemiPrime(i));
|
||||
}
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
//returns true or false depending if input was considered semiprime
|
||||
private static bool isSemiPrime(int c)
|
||||
{
|
||||
int a = 2, b = 0;
|
||||
while (b < 3 && c != 1)
|
||||
{
|
||||
if ((c % a) == 0)
|
||||
{
|
||||
c /= a;
|
||||
b++;
|
||||
}
|
||||
else
|
||||
{
|
||||
a++;
|
||||
};
|
||||
}
|
||||
return b == 2;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue