Computer Science, asked by pranjalsy, 1 year ago

WAP to enter 10 elements in array and print all prime numbers of the array.​

Answers

Answered by AadilPradhan
5

Answer:

#include<stdio.h>

#include<conio.h>

void main()

{

int ar[100],i,n,j,counter;

printf("Enter the size of the array- ");

scanf("%d",&n);

printf("\n Now enter the elements of the array");

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

{

scanf("%d",&ar[i]);

}

printf(" Array is :-");

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

{

printf("\t %d",ar[i]);

}

printf("\n All the prime numbers in the array are -");

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

{

counter=0;

for(j=2;j<ar[i];j++)

{

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

{

counter=1;

break;

}

}

if(counter==0)

{

printf("\t %d",ar[i]);

}

}

getch();

}

Output –

Enter the size of the array – 10

Now enter the elements of the array – 3 6 15 23 7 56 29 8 74 32

Array is – 3 6 15 23 7 56 29 8 74 32

All the prime numbers in the array are – 3 23 7 29


pranjalsy: thanks
Similar questions