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.
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.
Hey,
Why dont you use a for loop?
here it is:Code:for ( int n = 0, n >= 100, n++)
I hope this helps.Code:#include <iostream> using namespace std; int main() { for (int n = 3; n <= 100; n++) { // TO DO } return 0; }
Hey I have the code but its for java. The logic is same.
Try it. It give you first 100 prime numbers.
I hope this helps you.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 + " "); } } } } }
Here is a code to find out prime numbers between 1 - 100 :
Is this what you need?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(); }
Bookmarks