how do u find prime numbers in an array

Reply

Join Date: Feb 2007
Posts: 3
Reputation: srinath33 is an unknown quantity at this point 
Solved Threads: 0
srinath33 srinath33 is offline Offline
Newbie Poster

how do u find prime numbers in an array

 
0
  #1
Feb 18th, 2007
hlp please
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,171
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1439
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: how do u find prime numbers in an array

 
0
  #2
Feb 18th, 2007
if you search these threads you will find several threads on this topic.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 13
Reputation: nadith_cs is an unknown quantity at this point 
Solved Threads: 0
nadith_cs nadith_cs is offline Offline
Newbie Poster

Re: how do u find prime numbers in an array

 
1
  #3
Feb 18th, 2007
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....

e.g.

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

primArray[10]={2,3,5,7,11,13,17,19}
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....
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 3
Reputation: srinath33 is an unknown quantity at this point 
Solved Threads: 0
srinath33 srinath33 is offline Offline
Newbie Poster

Re: how do u find prime numbers in an array

 
0
  #4
Feb 18th, 2007
dude we need2 accept the numbers in an array.... so among those nos wi nid 2 find
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,050
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 331
Moderator
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: how do u find prime numbers in an array

 
0
  #5
Feb 18th, 2007
Speak English please. And once you do that, you can show some effort.
http://www.daniweb.com/techtalkforum...cement8-2.html
http://www.catb.org/~esr/faqs/smart-questions.html
"Technological progress is like an axe in the hands of a pathological criminal."
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 171
Reputation: Lazaro Claiborn is an unknown quantity at this point 
Solved Threads: 13
Lazaro Claiborn's Avatar
Lazaro Claiborn Lazaro Claiborn is offline Offline
Junior Poster

Re: how do u find prime numbers in an array

 
0
  #6
Feb 20th, 2007
Originally Posted by srinath33 View Post
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,145
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: how do u find prime numbers in an array

 
0
  #7
Feb 20th, 2007
I don't know how "u" does it. I do know how I'd do it.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 7
Reputation: goutham_see is an unknown quantity at this point 
Solved Threads: 0
goutham_see goutham_see is offline Offline
Newbie Poster

Re: how do u find prime numbers in an array

 
0
  #8
Feb 21st, 2007
  1. /* This program is for checking a single integer*/
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. main()
  5. {
  6. int a,i;
  7. printf("\nEnter a positive integer\n");
  8. scanf("%d",&a);
  9. if(a<=0)
  10. {
  11. printf("\nInvalid input\n");
  12. exit(1);
  13. }
  14. for(i=2;i<=a-1;i++)
  15. if(a%i==0)break;
  16. if(i==a)printf("\n%d is prime\n",a);
  17. else printf("\n%d is not a prime\n",a);
  18. }
  19.  
  20.  
  21. /* This is for elements in an array*/
  22. #include<stdio.h>
  23. #include<stdlib.h>
  24. #define MAX 5
  25. main()
  26. {
  27. int a[MAX],i,m;
  28. printf("\nEnter elements into array\n");
  29. for(m=0;m<=MAX-1;m++)
  30. {
  31. scanf("%d",&a[m]);
  32. if(a[m]>0)
  33. {
  34. for(i=2;i<=a[m]-1;i++) if(a[m]%i==0)break;
  35. if(i==a[m])printf("\n%d is prime\n",a[m]);
  36. else printf("\n%d is not a prime\n",a[m]);
  37. }
  38. else printf("\n%d is not positive\n");
  39. }
  40. }
Last edited by WaltP; Feb 21st, 2007 at 2:58 am. Reason: Added Code Tags -- please use them yourself. Instructions in the stickys.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC