After we learn how to check a number if it's a prime number or not, i bring you to learn how to make a prime number code with c#. But before we try to make a code, we must know what's prime number?
A Prime Number is a number who can be divided evenly only by 1, or itself.
And it must be a whole number greater than 1. so, do you have logic how to make prime number after you know definition prime number ?
all right, when we try to make a prime number, we must knowing a key of prime number and this is can be divided only by 1 or itself. and we will need divided on this program. divided on the program is %.
this is a code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace chapter_3_exercise_3
{
class PrimeNumber
{
static void Main(string[] args)
{
bool Value = false;
int f;
Console.WriteLine(" --> PRIME NUMBER APPLICATION ! <-- ");
Console.WriteLine ("Attention ! \nRule on this Program");
int A;
for (A = 1; A < 59; A = A + 1)
{
Console.Write("-");
Thread.Sleep (20);
}
Console.WriteLine("\n You Can Check Number untill you want. \n so, you just entered the number untill you want \n ");
int i;
for (i = 1; i < 59; i = i + 1)
{
Console.Write("-");
Thread.Sleep(20);
}
Console.WriteLine("\nEnter The Number : ");
int n = Int32.Parse(Console.ReadLine());
for (int e = 2; e <= n; e++)
{
for (f = 2; f < e; f++)
{
if (e % f == 0)
{
Value = true;
break;
}
}
if (Value == false)
Console.Write("{0} ", f);
else
Value = false;
}
Console.WriteLine("\n\n\n");
int K;
for (K = 1; K < 59; K = K + 1)
{
Console.Write("-");
Thread.Sleep(20);
}
Console.WriteLine("\n | --Thank you -- |");
int J;
for (J = 1; J < 59; J = J + 1)
{
Console.Write("-");
Thread.Sleep(20);
}
Console.ReadLine();
}
public static int i { get; set; }
}
}
when you execute this code will show :
this is will be happened if we entered 19 :
A Prime Number is a number who can be divided evenly only by 1, or itself.
And it must be a whole number greater than 1. so, do you have logic how to make prime number after you know definition prime number ?
all right, when we try to make a prime number, we must knowing a key of prime number and this is can be divided only by 1 or itself. and we will need divided on this program. divided on the program is %.
this is a code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace chapter_3_exercise_3
{
class PrimeNumber
{
static void Main(string[] args)
{
bool Value = false;
int f;
Console.WriteLine(" --> PRIME NUMBER APPLICATION ! <-- ");
Console.WriteLine ("Attention ! \nRule on this Program");
int A;
for (A = 1; A < 59; A = A + 1)
{
Console.Write("-");
Thread.Sleep (20);
}
Console.WriteLine("\n You Can Check Number untill you want. \n so, you just entered the number untill you want \n ");
int i;
for (i = 1; i < 59; i = i + 1)
{
Console.Write("-");
Thread.Sleep(20);
}
Console.WriteLine("\nEnter The Number : ");
int n = Int32.Parse(Console.ReadLine());
for (int e = 2; e <= n; e++)
{
for (f = 2; f < e; f++)
{
if (e % f == 0)
{
Value = true;
break;
}
}
if (Value == false)
Console.Write("{0} ", f);
else
Value = false;
}
Console.WriteLine("\n\n\n");
int K;
for (K = 1; K < 59; K = K + 1)
{
Console.Write("-");
Thread.Sleep(20);
}
Console.WriteLine("\n | --Thank you -- |");
int J;
for (J = 1; J < 59; J = J + 1)
{
Console.Write("-");
Thread.Sleep(20);
}
Console.ReadLine();
}
public static int i { get; set; }
}
}
when you execute this code will show :
this is will be happened if we entered 19 :

Post a Comment