answersLogoWhite

0


Best Answer

#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(); }

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

#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(); }

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

#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();

}

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

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

}

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

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 answer is:
User Avatar

User Avatar

Wiki User

13y ago

/*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();

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write a c program to check whether a no is prime or not?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write an algorithm to check whether a number is a prime number or not?

You can write out this algorithm. This will then be programmed into the device to make determining prime numbers easier.


Write a java programme to check whether the number is twin prime or not?

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.


With a given big integer number which is the product of two prime numbers how do you find them?

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.


Write a shell script to check whether the given input is prime or not?

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


How do you write a VBnet program to find the prime numbers between 100 to 200?

VBnet program to find the prime numbers between 100 to 200?


What is the largest prime no that is stored in 8 bit pattern?

Write your own prime number program and find out.


How can I write a program to display prime numbers from 1 to 100?

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.


How do you find prime numbers between 2 and 70?

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.


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.


How do you write a program in objective c numbers 1-100 prime numbers?

fdsgfhgdfhgdf


Does any whole number multiply to get 29?

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).


Program for print prime all number from 1 to 100 in foxpro?

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.