Need Help. Why it can't Print Exact Output (in C#)?
/* Write a C# program to compute the sum of the first 500 prime numbers. Go to the editor Output: 3682913 */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace ConsoleApplication8 { class Program { static void Main(string[] args) { int num, i,l; int sum = 0; l = 0; for (num = 1; ;num++ ) { int k = 0; for (i = 1; i <= num; i++) { if (num % i == 0) { k++; } } if (k == 2) { Console.WriteLine("Number is {0}", num); sum += num; l++; if (l == 500) { Console.WriteLine("Sum is {0}", sum); break; } } else { } } Console.WriteLine("Sum is {0}", sum); Console.WriteLine("Total Number is {0}", l); } } }