#include<stdio.h> #include<conio.h> int i=1, count=0,n; clrscr(); printf("Enter Any Number"); scanf("%d", &n); while(i<n) if(n%i==0) { count++; i++; } if(count==2) printf("Given Number is Prime"); else printf("Given Number is not Prime"); getch(); }
#include<stdio.h> #include<conio.h> void main() { int num,i=2; print ("\n enter any number"); scanf("%d",&num); while(i<num) { if(num%i==0) { printf("\n number is not prime"); break; } else { i++; } getch(); }
#include<iostream.h> #include<conio.h>
int main()
{
clrscr();
cout<<"PROGRAM TO CHECK IF THE NUMBER IS PRIME OR NOT:"<<endl;
cout<<"Enter a number:";
int n;
cin>>n;
for(int i=2;i<n;i++)
{
if(n%i==0)
{
cout<<"THE NUMBER IS NOT PRIME"<<endl;
}
}
if(i==n)
{
cout<<"THE NUMBER IS PRIME"<<endl;
}
else
{
exit(1);
}
getch();
return 0;
}
Note: the exit(1) statment needs protype
and on not prime numbers it execute the full loop and print the result like this
enter the number
n=6
the number is not prime
the number is not prime
the number is prime
instead of it try this code with a little modification .
i aknowledge your work.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"PROGRAM TO CHECK IF THE NUMBER IS PRIME OR NOT:"<<endl;
cout<<"Enter a number:";
int n;
cin>>n;
for(int i=2;i<n;i++)
{
if(n%i==0)
{
cout<<"THE NUMBER IS NOT PRIME"<<endl;
goto g1;
}
}
if(i==n)
{
cout<<"THE NUMBER IS PRIME"<<endl;
}
g1:
getch();
}
bool isPrime(int n)
{
int i=2; //1 is not a prime so start from 2
//run a loop to check if any number divides that number
//we are checking all the numbers below the given number
while(i < n)
{
if(n % i == 0) //if any number below a given number divides it then not prime
return false;
i++;
}
return true; //if all number is checked fior divisibility and no number divides it its a prime
}
Linux or Windows or any other platform makes no difference. All you need is the following user-defined function:
bool isprime(unsigned long long p)
{
if( p<=1 ( p>2 && p%2==0 ))
return( false );
unsigned long long max = (unsigned long long)sqrt(( double ) p ) + 1;
for( unsigned long long i=3; i<=max; i+=2 )
if( p%i==0 )
return( false );
return( true );
}
/*this is a program to check wether a no is prime or composite*/
#include<stdio.h>
#include<conio.h>
void main()
{
int no,i;
clrscr();
printf(" Enter the Number U want to check:");
scanf("%d",&no);
i=2;
while(i<=no-1)
{
if(no%i==0)
{
printf(" %d is composite",no );
break;
}
i=i+1;
}
if(no==i)
printf("%d is a Prime number",no);
getch();
}
Loop through some numbers - for example, 2 through 100 - and check each one whether it is a prime number (write a second loop to test whether it is divisible by any number between 2 and the number minus 1). If, in this second loop, you find a factor that is greater than 1 and less than the number, it is not a prime, and you can print it out.
Begin Read num for(i=2; i<num; i++) if(num%2==0) then print "the number is not a prime no."; else if print "the number is prime"; end if Stop
look man that would take alot >>> Ill give you the way =============================================================================== this answer i write it now on net ! i read about that befor in it uni where i study i will chick out the answer and re write it best wishes 2024
int number; int i=2; while (i<number) { if(number%i==0) { printf("Not a prime no."); break; } else printf("number entered is prime"); getch(); }
(defun prime (num) (if (< 2 num) (do ((dividend 2 (1 + dividend)) (chk-to (sqrt num))) ((equal (rem num dividend) 0)) (when (<= chk-to dividend) (return t))) t))
You can write out this algorithm. This will then be programmed into the device to make determining prime numbers easier.
Find a prime number, add 2 to the number. Check if the new number is prime. IE : 3 is prime. 3+2 =5. 5 is prime. (3,5) are twin primes.
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.
shell script for check whether the given no is prime or not??echo "input any number:"read nono=`expr $no`i=`expr 2`while [ $i -lt $no ]doif [ `expr $no % $i` -eq 0];thenecho "$no is not a prime no.."break 2fii=`expr $i +1`doneif [ $i -eq $no ];thenecho "$no is a PRIME no..."fi
VBnet program to find the prime numbers between 100 to 200?
Write your own prime number program and find out.
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.
You can check each individual number, whether it is a prime number. For numbers below 100, it is enough to check whether they are divisible by 2, by 3, by 5, and by 7. If a number is divisible by none of these, it is a prime number.
By learning how to program on C+.
fdsgfhgdfhgdf
29 is a prime number, meaning it has no smaller factors. For any number up to 120, to check whether it is prime or not, it is sufficient to check whether it is divisible by the first four prime numbers (2, 3, 5 and 7).
Prime numbers are numbers that are only divisible by themselves and the number 1. You can write a program to print all prime numbers from 1 to 100 in FoxPro.