|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
To write first 100 prime numbers in c++ program. Hello friends, I want a simple program to write 100 prime numbers in c++ Please help me with the code. How to write c++ program the first 100 prime numbers. Thanks in advance. |
#2
| |||
| |||
Re: To write first 100 prime numbers in c++ program. Hey, Why dont you use a for loop? Code: for ( int n = 0, n >= 100, n++) Code: #include <iostream> using namespace std; int main() { for (int n = 3; n <= 100; n++) { // TO DO } return 0; } ![]() |
#3
| |||
| |||
Re: To write first 100 prime numbers in c++ program. Hey I have the code but its for java. The logic is same. Try it. It give you first 100 prime numbers. Code: public class whileprime { public static void main(String args[]) { int num = 4; int count = 0; System.out.println("First 100 Prime Numbers: "); System.out.println("1"); System.out.println("2"); System.out.println("3"); while(count < 100) { num++; if(num % 2 != 0) { int dv = 3; while((num % dv != 0)&&(dv <= ((num - 1) / 2))) { dv++; } if(num % dv != 0) { count++; System.out.println(num + " "); } } } } } |
#4
| |||
| |||
Re: To write first 100 prime numbers in c++ program. Here is a code to find out prime numbers between 1 - 100 : Code: void main() { int i,number=1; clrscr(); while(number<=100) { i=2; while(i<=number) { if(number%i==0) break; i++; } if(i==number) printf("\n%d is Prime",number); number++; } getch(); } |
![]() |
|
Tags: 100 prime numbers, c program |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Program to print GCD of given numbers | Bhavesh_seth | Software Development | 5 | 15-03-2011 08:03 PM |
Need C program code to count numbers of negative & positive numbers | Sarfaraj Khan | Software Development | 5 | 16-01-2010 02:00 PM |
Program to print odd and even numbers | roodiii | Software Development | 3 | 30-11-2009 02:13 PM |
What is the program to swap two numbers? | Bharat89 | Software Development | 3 | 26-11-2009 09:37 AM |
Write numbers in arabic | Neider | Off Topic Chat | 3 | 21-08-2009 06:37 PM |