Computer Science, asked by blackmind143, 1 year ago

write a C program to print Prime numbers from a given array

Answers

Answered by armaan2305shaikh
2

Prime number program in C language

#include<stdio.h>

 

int main()

{

  int n, i = 3, count, c;

 

  printf("Enter the number of prime numbers required\n");

  scanf("%d",&n);

 

  if ( n >= 1 )

  {

     printf("First %d prime numbers are :\n",n);

     printf("2\n");

  }

 

  for ( count = 2 ; count <= n ;  )

  {

     for ( c = 2 ; c <= i - 1 ; c++ )

     {

        if ( i%c == 0 )

           break;

     }

     if ( c == i )

     {

        printf("%d\n", i);

        count++;

     }

     i++;

  }

 

  return 0;

}

HOPE THIS HELPS YOU

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