how to find the given number is prime or not?

Answer Posted / rahul tiwari

main()
{
int n,ctr=2,flag=0;
printf("enter the number to be checked\n");
scanf("%d",&n);
for(ctr=2;ctr<=n/2;ctr++)
{
if(n%ctr==0)
{
flag=1;
break;
}
}
if(flag==1)
printf("the given number is prime\n");
else
printf("the given number is not prime\n");
flag=9
getch();
}

Is This Answer Correct ?    8 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the advantages and disadvantages of pointers?

570


How can I generate floating-point random numbers?

596


any function have arguments one or more OR not . it is compulsary a) any function compulsary have one or more arguments b) any function did not have arguments. It is not compulsary c) it is optional it is not compulsary d) none of the above

637


What is getch?

624


What are the c keywords?

742






What are the types of data structures in c?

594


Is c pass by value or reference?

587


When would you use a pointer to a function?

578


Explain what are bus errors, memory faults, and core dumps?

782


Differentiate between Macro and ordinary definition.

718


how should functions be apportioned among source files?

616


What is the use of parallelize in spark?

568


What is clrscr ()?

627


What are linked lists in c?

641


What are local variables c?

539