Computer Science, asked by kalikantroy27, 4 months ago

IN JAVA WITH OUTPUT

Write a program to input a number and check it for prime or not prime.​

Answers

Answered by lehav8084
0

Answer:

In this c program, we will take an input from the user and check whether the number is prime or not.

#include<stdio.h>

int main(){

int n,i,m=0,flag=0;

printf("Enter the number to check prime:");

scanf("%d",&n);

m=n/2;

for(i=2;i<=m;i++)

{

Explanation:

hope this helps u.

please mark me as brainliest.

Answered by amansarrafas24payxgs
2

Answer:

import java.util.*;

class Prime

{

public void main()

{

Scanner sc = new Scanner (System.in);

System.out.println("Enter a number: ");

int n = sc.nextInt();

int count = 0;

for(int i = 2;i <= n;i++)

{

if(n%i == 0)

{

count++;

}

}

if(count == 1)

{

System.out.println(n + " is a Prime Number");

}

else

{

System.out.println(n + " is not a Prime Number");

}

}

}

I hope you find it useful... If you have any query do comment, I will try to solve it...

Similar questions