Reputation:
using System;
public class Test
{
public static void Main()
{
int n = 600851475143;
int x = 1;
While (x<n)
{
if(n%x==0)
{
Console.WriteLine(x);
}
x++;
}
}
}
Gives me a { out of place error, but I can't see whats wrong. Anyone?
Upvotes: 0
Views: 162
Reputation: 69973
While
should not be capitalized, and your value of n
is too large for an int.
You don't seem to have a problem with braces. If you fix those two errors it should compile.
Edit: The code file you posted is a completely different error than the one you posted in the question. A C# program can only have one entry point, which is what public static void Main()
does. If you copy and pasted the method signature from the Program
file it is not going to compile. Change Main
to any other valid signature and it should compile.
Upvotes: 6
Reputation: 218722
While (x<n)
should be while (x<n)
And you are assigining a long
value to an int
variable.
The maximum value an int
varibale can hold is 2,147,483,647; So you may change that to long
long n = 600851475143;
Upvotes: 2