using namespace std; #include< iostream> #include< stdlib.h> int main() { int nb,r=0; cost< < "Enter a number: "; cin> > nb; for(int i = 1 ; i <= nb ; i++ ) { if(nb % i == 0) { r++; } } if(r> 2) cost< < nb< < " is not a prime number"< < endl; else cost< < nb< < " is a prime number"< < endl; system("pause"); } |
#include< stdio.h> #include< stdlib.h> int main() { int number=1 counter=0; int i,r,n=100; while(counter< n){//the first n r=0; //to count the number of divisors number++; for (i=1 ; i<=number; i++) { if ((number%i)==0) r++; } if(r==2)//The prime number is divided into 1 and itself { printf(" %d \n", number); //we increment the counter counter++; } } system("pause"); } |
#include< stdio.h> #include< stdlib.h> int main() { int number=1 counter=0; int i,r,n=100; printf("Prime numbers less than %d are:\n",n); while(number < n){//as long as number < n then r=0; //to count the number of divisors number++; for (i=1 ; i<=number; i++) { if ((number%i)==0) r++; } if(r==2)//The prime number is divided into 1 and itself { printf(" %d \n", number); } } system("pause"); } |
Please disable your ad blocker and refresh the window to use this website.