Thursday, 21 July 2016

WAP TO ACCEPT N NUMBERS AND STORE ALL PRIME NUMBERS IN AN ARRAY CALLED PRIME. DISPLAY THIS ARRAY.

#include<stdio.h>
main()
{
int num,j,i,prime[50],n,p=0,c=0,d=0;
printf("Enter value of n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&num);
for(j=1;j<=num;j++)
{
if(num%j==0)
p=p+1;
}
if(p==2)
{
prime[c]=num;
c++;
d++;
}
p=0;
}
printf("prime numbers from the numbers are\n");
for(i=0;i<d;i++)
{
printf("%d ",prime[i]);
}
}

No comments:

Post a Comment