+ 1
Time limit exceeded
I've got a code, whis is to find out if the number you entered is prime, but if I type 8, then the output is Time limit exceeded. Why is this happening? And how to correct it. Is it because of my phone (lenovo A319)? http://www.sololearn.com/app/csharp/playground/cr5bphXnQ6dg/ this is the code
5 Answers
+ 3
Hi, still there?
I just tried to rewrite your code in a way that it still looks similar to how you coded it, for you to easily understand its flow.
If this work perfectly fine, just give me an Up vote, thanks! Hope this helps.
--
UPDATED VERSION:
using System;
namespace IsPrime
{
class Program
{
static void Main(string[] args)
{
int num = int.Parse(Console.ReadLine());
Console.WriteLine(Prime(num));
}
private static bool Prime(int num)
{
if (num > 1)
{
for (int i = 2; i < num; i++)
{
if (num % i == 0) return false;
}
return true;
}
else return false;
}
}
}
+ 1
When I try 8 it writes False and then an unhandled exception
+ 1
I'm sorry, I forgot to remove the while(true)
--
I updated the code, try it again now.
+ 1
Yes, that works. But I still can't understand why I receive Time Limit exceeded
0
Its because your not gay