Q:

C Program to check prime numbers in an array

0

C Program to check prime numbers in an array

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <stdio.h>


int isPrime(int num)
{
	int i; //loop counter
	
	int flag=0; 
	
	for(i=2; i<num/2; i++)
	{
		if(num%i ==0)
		{
			flag =1;
			break;
		}
	}
	
	if(flag==1)
		return 0;
	else
		return 1;
}

int main()
{
	int loop; //loop counter
	
	int arr[]={100, 200, 31, 13, 97, 10, 20, 11};
	
	int len = sizeof(arr)/sizeof(arr[0]);
	
	
	
	for(loop=0; loop<len; loop++)
	{
		printf("%3d - %s\n",arr[loop],(isPrime(arr[loop])?"Prime":"Not Prime"));
	}
	
	printf("\n");
	
	return 0;	
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now