how to find the given number is prime or not?

Answer Posted / amit kumar

#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==0)
printf("the given number is prime\n");
else
printf("the given number is not prime\n");
getch();
}

Is This Answer Correct ?    2 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is volatile variable in c with example?

588


What are comments and how do you insert it in a C program?

742


What is the use of ?: Operator?

667


How to draw the flowchart for structure programs?

8762


What is a node in c?

550






Why is this loop always executing once?

617


What is non linear data structure in c?

577


Which is better between malloc and calloc?

671


What is a nested formula?

605


Explain what is the difference between the expression '++a' and 'a++'?

627


#include int main(){ int i=10; int *ptr=&i; *ptr=(int *)20; printf("%d",i); return 0; } Output: 20 can anyone explain how came the output is 20

1267


What is the purpose of main( ) in c language?

623


What are terms in math?

594


can anyone suggest some site name..where i can get some good data structure puzzles???

1643


Why c is called a middle level language?

634