Prime numbers from 1 to 100

Reply

Join Date: Nov 2009
Posts: 15
Reputation: imolorhe is an unknown quantity at this point 
Solved Threads: 0
imolorhe imolorhe is offline Offline
Newbie Poster

Prime numbers from 1 to 100

 
-3
  #1
20 Days Ago
Please, I need help in this little problem of printing all the prime numbers from to 100. Please, if you have more than one method to the question, I would really appreciate it. I also need it as soon as possible. Thanks.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 18
Reputation: Chilton is an unknown quantity at this point 
Solved Threads: 2
Chilton Chilton is offline Offline
Newbie Poster
 
-1
  #2
20 Days Ago
Well, you can start off with the first two: 2, and 3, and store them in an array. From there, think of the conditions for a number to be prime and implement it, keeping in mind to compare each successive value against the prime array.

Here's hoping it helps.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 4
Reputation: mruthyunjaya is an unknown quantity at this point 
Solved Threads: 0
mruthyunjaya mruthyunjaya is offline Offline
Newbie Poster
 
-2
  #3
19 Days Ago
  1. #include <math.h>
  2. #include <stdio.h>
  3.  
  4. int main(void){
  5. int i, j, isPrime;
  6. for(i = 2 ; i <= 100 ; i++){
  7. isPrime = 1;
  8. for(j = 2 ; j <= i ; j++) {
  9. if( i == j)
  10. continue;
  11. else if( i % j == 0)
  12. isPrime = 0;
  13. }
  14. if(isPrime)
  15. printf("%d, ", i);
  16. }
  17. printf("\n");
  18. return 0;
  19. }

hope this helps...
Last edited by mruthyunjaya; 19 Days Ago at 7:58 am. Reason: wrong variable name
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 3
Reputation: vivek01anand is an unknown quantity at this point 
Solved Threads: 0
vivek01anand vivek01anand is offline Offline
Newbie Poster
 
-2
  #4
19 Days Ago
#include<stdio.h>
main()
{
int i,j,flag=0;
for(i=1:i<=100;i++)
{
flag=0;
for(j=2;j<=(i/2);j++)
{
if(i%j==0)
{
flag=1;
break;
}
}
if(flag==1)
printf("%d\t",i);
}
}
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 18
Reputation: Chilton is an unknown quantity at this point 
Solved Threads: 2
Chilton Chilton is offline Offline
Newbie Poster
 
1
  #5
19 Days Ago
And here I thought the point wasn't to simply give the answer.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC