12/*Write a ‘C’ program to accept ‘n’ numbers and store all prime numbers in an array and display this array*/


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a[50],i,j,b[50],limit,k=0,flag=0;
clrscr();
printf(“\n Enter the numbers:”);
scanf(“%d”,&limit);
printf(“\n Enter %d elements\n”,limit);
for(i=0;i<limit;i++)
{
scanf(“%d”,&a[i]);
}
for(i=0;i<limit;i++)
{
for(j=2;j<=a[i]/2;j++)
if((a[i]%j)==0)
flag=1;
if(flag==0)
b[k++]=a[i];
flag=0;
}
printf(“Prime number are:”);
for(i=0;i<k;i++)
printf(“%d\t”,b[i]);
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s