write the program for prime numbers?

Answer Posted / anjana rao .ch

\*Write a program wither given number is prime or not */
\*I think it is different to others (BY ANJAN)*/
#include<stdio.h>
main()
{
int n,a=3;
printf("Enter Number");
scanf("%d",&n);
if(n==2)
{
printf("Given Number is PRIME");
exit (0);
}
if(n==3)
{
printf("Given Number is PRIME");
exit (1);
}
if(n%2==0)
{
printf("Given Number is NOT PRIME");
exit (2);
}
while(a<=n/2)
{
if(n%a==0)
{
printf("Given Number is NOT PRIME");
exit (3);
}
a=a+2;
}
printf("Given Numbr is PRIME");
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is variable and explain rules to declare variable in c?

558


Why c is called top down?

631


What is meant by initialization and how we initialize a variable?

590


to find the closest pair

1825


Explain the meaning of keyword 'extern' in a function declaration.

728






How can you be sure that a program follows the ANSI C standard?

1133


which of the following is allowed in a "C" arithematic instruction a) [] b) {} c) () d) none of the above

1140


Explain what could possibly be the problem if a valid function name such as tolower() is being reported by the c compiler as undefined?

587


Is swift based on c?

642


the statement while(i) puts the entire logic in loop. this loop is called a) indefinite loop b) definite loop c) loop syntax wrong d) none of the above

609


An expression to whose value an operater is applied a) operand b) variable c) constant d) all of the above

661


Why do we use null pointer?

609


Is multithreading possible in c?

571


Write a program for Overriding.

692


Is there a way to jump out of a function or functions?

638