using System;
class MainClass
class MainClass
{
public static void Main()
public static void Main()
{
int num;
int i;
int factor;
bool isprime;
for(num = 2; num < 20; num++)
int num;
int i;
int factor;
bool isprime;
for(num = 2; num < 20; num++)
{
isprime = true;
factor = 0;
for(i=2; i <= num/2; i++)
isprime = true;
factor = 0;
for(i=2; i <= num/2; i++)
{
if((num % i) == 0)
if((num % i) == 0)
{
isprime = false;
factor = i;
}
}
if(isprime)
Console.WriteLine(num + " is prime.");
else
Console.WriteLine("Largest factor of " + num +
" is " + factor);
}
}
}
isprime = false;
factor = i;
}
}
if(isprime)
Console.WriteLine(num + " is prime.");
else
Console.WriteLine("Largest factor of " + num +
" is " + factor);
}
}
}
No comments:
Post a Comment