FY_BCA_C_SLIP 11_2




Slip no : 11_2 accept n nos from user and stror all prime no into array and display this array */


#include<stdio.h>
#include<conio.h>

int main()
{
int a[20],prime[10]; int n,i,j,k,flag;

printf("\n enter how many nos : "); scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter no : "); scanf("%d",&a[i]);
}

k=0;
for(i=0;i<n;i++) { flag=0;

for(j=2;j<=a[i]/2;j++)
{
if(a[i]%j==0) //not prime
{
flag=1;break;
}
}
if(flag==0)
{
prime[k]=a[i];
k++;
}
}

printf("\n Given nos are : "); for(i=0;i<n;i++)
{
//        printf("\n Enter no : "); printf("%d\t",a[i]);
}

printf("\n prime nos are : ");
for(i=0;i<k;i++)
{
//        printf("\n Enter no : "); printf("%d\t",prime[i]);

}
getch();

}

No comments:

Post a Comment