Danyal
✅ This shouldn't work for 2 and 3 but it does
Prime number checker:
static void Plus(int number)
{
Func<int, int> addone = x => (number + 1) / 6;
Func<int, int> minusone = y => (number - 1) / 6;
if (addone(number) % 6 != 0 || minusone(number) % 6 != 0)
{
Console.WriteLine("{0} is not prime", number);
}
else
{
Console.WriteLine("{0} is prime", number);
}
}
static void Plus(int number)
{
Func<int, int> addone = x => (number + 1) / 6;
Func<int, int> minusone = y => (number - 1) / 6;
if (addone(number) % 6 != 0 || minusone(number) % 6 != 0)
{
Console.WriteLine("{0} is not prime", number);
}
else
{
Console.WriteLine("{0} is prime", number);
}
}
38 replies
✅ After a number is entered the program ends
After the number is input the program ends and it doesn't output anything else.
Console.WriteLine("Enter a positive whole number");
int NumberIn = Int32.Parse(Console.ReadLine());
int NumberOut = 0;
int Count = 0;
while (NumberIn > 0)
{
Count++;
int PartValue = NumberIn % 2;
NumberIn = NumberIn / 2;
for (int i = 1; i < Count; i++)
{
PartValue = PartValue * 10;
}
NumberOut = NumberOut + PartValue;
}
Console.WriteLine("The result is: {0}", NumberOut);
Console.WriteLine("Enter a positive whole number");
int NumberIn = Int32.Parse(Console.ReadLine());
int NumberOut = 0;
int Count = 0;
while (NumberIn > 0)
{
Count++;
int PartValue = NumberIn % 2;
NumberIn = NumberIn / 2;
for (int i = 1; i < Count; i++)
{
PartValue = PartValue * 10;
}
NumberOut = NumberOut + PartValue;
}
Console.WriteLine("The result is: {0}", NumberOut);
12 replies