Mencetak Bilangan Prima C# Posted by Unknown on November 30, 2014 Get link Facebook X Pinterest Email Other Apps using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace mencetak_bilangan_prima { class Program { static void Main(string[] args) { int bilangan; Console.Write("Masukkan batas bilangan : "); bilangan = Convert.ToInt32(Console.ReadLine()); int temp=0; Console.WriteLine(); Console.WriteLine("Bilangan prima dari 1 sampai {0} adalah ", bilangan); for (int i = 1; i <=bilangan; i++) { for (int j = 1; j <= i; j++) { if (i % j == 0) { temp += 1; } } if (temp == 2) { Console.Write(i+" "); } temp = 0; } Console.ReadKey(); } } } Comments
Comments
Post a Comment