Start New Discussion within our Software Development Community

first write a program to catch all the prime numbers in to an array in a given or a chosen range....
and compare the elements of prime numbers with the each element of the array u want...
if one of ur array element is equal to a element of prime number array,,that means it's a prime number....


A[4]={1,5,3,4,17}; //range is 1 to 20

now compare array 'A' with the each element of 'primArray'.

if u find hard to write a program to catch prime numbers of a given range to an array email me....

this helped me

dude we need2 accept the numbers in an array.... so among those nos wi nid 2 find

hlp please

A prime number is a number that can only be evenly divided by itself and 1. Let number x equal a given element in the array. Now you can for loop from 2 to x-1 and use the modulus operator. If the resulting value is equal to 0 then it is certainly not a prime.

Good luck, LamaBot

/* This program is for checking a single integer*/
 int a,i;
 printf("\nEnter a positive integer\n");
  printf("\nInvalid input\n");
 if(i==a)printf("\n%d is prime\n",a);
 else printf("\n%d is not a prime\n",a);

/* This is for elements in an array*/
#define MAX 5
 int a[MAX],i,m;
 printf("\nEnter elements into array\n");
          for(i=2;i<=a[m]-1;i++) if(a[m]%i==0)break;
          if(i==a[m])printf("\n%d is prime\n",a[m]);
          else printf("\n%d is not a prime\n",a[m]);
    else printf("\n%d is not positive\n");
This article has been dead for over six months. Start a new discussion instead.