C program to accept 10 elements in an array and display all prime numbers

Example#1

#include<stdio.h>
int main()
{
	int n,i,j,a[30];
	printf("Enter the size of array:");
	scanf("%d",&n);
	printf("\nEnter the array elements:");
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	printf("\nArray elements are:");
	for(i=0;i<n;i++)
	{
		printf("%d ",a[i]);
	}
	printf("\nPrime numbers are:");
	for(i=0;i<n;i++)
	{
		for(j=2;j<a[i];j++)
	   {
        if(a[i]%j==0)
		break;
	   }
	 if(a[i]==j)
	 {
	 	printf("%d ",a[i]);
	 }
	}
	return 0;
}

Output:

Facebook Comments

Back to Top