how to find the given number is prime or not?

Answer Posted / shrikanth s.hallikhed

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,flag=0,ctr;
printf("enter the number to be checked\n");
scanf("%d",&n);
for(ctr=2;ctr<=sqrt(n);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");
getch();
}

Is This Answer Correct ?    3 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

There seem to be a few missing operators ..

608


What is bubble sort in c?

627


Why doesnt long int work?

602


explain how do you use macro?

658


write a program to convert a expression in polish notation(postfix) to inline(normal) something like make 723+* (2+3) x 7 (not sure) just check out its mainly printing expression in postfix form to infix.

2257






What is a example of a variable?

538


Explain can the sizeof operator be used to tell the size of an array passed to a function?

585


Is it fine to write void main () or main () in c?

537


How the c program is executed?

624


How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same

645


Can you explain the four storage classes in C?

635


Why is c fast?

595


What is the use of parallelize in spark?

568


Why does not c have an exponentiation operator?

620


What is function prototype in c language?

606