Math, asked by svvk2866, 11 months ago

Program to find whether a number is prime

Answers

Answered by riya27042001
0

Answer:

Step-by-step explanation:

if an no. is prime only 1 and that no. itself will be able to divide that no.

eg:-13 ,as only 1 and 13 can divide it

Answered by Anonymous
0

Answer:

import java.util.*;

class Prime_no

{

   public static void main()

   {

       Scanner sc=new Scanner(System.in);

       System.out.println("Enter number of elements to be entered");

       int n=sc.nextInt();

       int a[]=new int[n];

       int f;

       System.out.println("Enter "+n+" elements");

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

       a[i]=sc.nextInt();

       System.out.println("Prime numbers:");

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

       {

           f=0;

           for(int j=1;j<=a[i];j++)

           {

               if(a[i]%j==0)

               f++;

           }

       if(f==2)

           System.out.println(a[i]);

       }

   }

}

Similar questions