Not tested:
void printPrimes(int n) {
int a = 0, b = 0;
float c = 0.0f;
bool isp = true;
int primes = 0;
while(true) {
a++;
do {
b++;
if(b > 1) {
c = (float)a/(float)b;
if(c = (int)c)
if(b != a) {
isp = false;
break;
}
else
isp=true;
}
} while(b<a);
if(isp) {
primes++;
std::cout << a << endl;
}
if(primes > n)
break;
b = 0;
c = 0;
isp = true;
}
}
void main() {
printPrimes(10);
}
Use Wolfram|Alpha... go to the related link below, Wolfram|Alpha, and type in (is __ (number) prime) and then the program will compute that and tell you if it is prime or composite.
Write your own prime number program and find out.
see the program
program to find prime number in 8085 microprocessor
Simply use a for loop (i) that runs from 2 to N-1. Checking if N % i 0 then its a prime number.
First write a program to generate the prime number. After one prime number was generated, divide the big int number by the prime number. If the remainder is zero then quotient is the second prime number ( also it is important to check whether the quotient is prime number or not because sometimes you will get wrong answer). Repeat the process until you get the result.
#include<iostream.h> #include<conio.h> int main() { int i,n; clrscr(); cout<<"PROGRAM TO CHECK IF THE NUMBER IS PRIME OR NOT:"<<endl; cout<<"Enter a number:"; cin>>n; for(int i=2;i<n;i++) { if(n%i==0) cout<<"\nTHE NUMBER IS COMPOSITE"<<endl; else cout<<"\nTHE NUMBER IS PRIME"<<endl; } return 0; }
There are several shell programs available for download on the Internet that will generate prime numbers. The best way to find a prime number is through calculation, however.
The easiest, but not the most efficient way, to program this is to take your number "n" and test all the numbers from 2 to n-1 to see if they divide n, if none of them do, then n is prime.
Write a function that implements an algorithm that checks to see if a particular integer is prime (returning a boolean). Write a program that uses that function on each number from 1 to 100, and if true, displays that number.
Oh, what a lovely request! In FoxPro, you can create a program to print all prime numbers from 1 to 100 by using a loop to check each number for divisibility only by 1 and itself. If it meets this criteria, you can print it out on the screen. Remember, every number is unique and special, just like a happy little tree in a vast forest.
#include<iostream.h> #include<conio.h> void prime(int n) { clrscr(); int num; cout<<"enter the numbers"<<endl; cin>>num; prime(num); getch(); } void prime(int n) { int prime=1,i; for(i=2;i<=n/2;i++) if(n%i==1) prime=0; if(prime==1) cout<<"the number"<<n>>"is prime"; else cout<<"the number"<<n<<"is not prime"; }