How To Write A Program In C#(dotnet) For Checking Given Number Is Prime Or Not?

2

2 Answers

Anonymous Profile
Anonymous answered

To check the prime number,use these code



class AB
{
public static void main()
{
console.write("Enter an number: ");
int num;
num=convert.ToInt32(console.ReadLine());
int k;
k=0;
for(int i=1;i<=num;i++)
{
if(num%i==0)
{
k++;
}
}
if(k==2)
{
console.WriteLine("Enetred a Prime number and the largest factor: ")
}
else
{
console.WriteLine("Not a Prime Number");
}
console.ReadLine();
}
}
}

Anonymous Profile
Anonymous answered
Void main()

{

int a,c=0,I,n;

clrscr();

printf("Enter number = n");

scanf("%d",&n);

for (I=0; I<=n; I++)

{

a = n%I;

if (a==0)

{

c=c+1;

}

}

if(c==2)

printf("The number is prime");

else
printf("It is not prime");

}

enjoy blurting :)

Answer Question

Anonymous