COOLINTERVIEW.COM
LANGUAGES
C DETAILS
Question : |
How can we find out prime numbers from 1 to 50?
 Posted by: pooja Date: 11/15/2008
Contact Author
|
Answer : |
#include<stdio.h> #include<conio.h> void main() { int i,j,c,n; clrscr(); for(i=2;i<50;i++) { c=0; for(j=2;j<i;j++) { if(i%j==0) c++; } if(c==0) printf("%d ",i); } getch(); }
 Posted by: sudheer
Contact Author
a better algo..... #include<math.h> #include<stdio.h> void main() { int i,j,c,n; clrscr(); for(i=2;i<50;i++) { c=0; for(j=2;j<sqrt(i);j++) { if(i%j==0) c++; } if(c==0) printf("%d ",i); } getch(); }
 Posted by: jaideep
Contact Author
main(){ int a,b,c; a=2; while(a<=50){ b=a-1; while(b>1){ if(a%b==0) printf("it is a%d prime number",a);} a++; }
 Posted by: nagaraju.botsa
Contact Author
#include<math.h> #include<stdio.h> void main() { int i,j,c,n; clrscr(); for(i=2;i<50;i++) { c=0; for(j=2;j<sqrt(i);j++) { if(i%j==0) c++; } if(c==0) printf("%d ",i); } getch(); }
 Posted by: ucm
Contact Author
© CoolInterview.com
Today's Special: Get Free Magazine from SAP now!
A D V E R T I S E M E N T
|
If you have the better answer, then send it to us. We will display your answer after the approval.
   
Rate the above answer. Help us to know about the answer.
Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.
| Notify me when better answer is posted!
|
View ALL C Interview Questions
|
Google
Search
CoolInterview.com is a part of Vyom Network.
Copyright ©2003-2009 Vyom Technosoft Pvt. Ltd., All Rights Reserved. Privacy Policy
Page URL: http://www.coolinterview.com/interview/16178/Default.asp?cachecommand=bypass
Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial
1.39
|