Q:

C Program to delete prime numbers from an array

1

C Program to delete prime numbers from 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 i,j; //loop counters
	
	int arr[]={100, 200, 31, 13, 97, 10, 20, 11};
	
	int len = sizeof(arr)/sizeof(arr[0]);
	
	
	for(i=0; i<len; i++)
	{
		if(isPrime(arr[i]))
		{
			
			for(j=i; j<len; j++)
			{
				arr[j] = arr[j+1];
			}
			
			i--;
			
			len--;			
		}
	}
	
	
	printf("Array elements after removing prime numbers:\n");
	for(i=0; i<len; i++)
		printf("%3d\n",arr[i]);
	
	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