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
What is volatile variable in c with example?
What are comments and how do you insert it in a C program?
What is the use of ?: Operator?
How to draw the flowchart for structure programs?
What is a node in c?
Why is this loop always executing once?
What is non linear data structure in c?
Which is better between malloc and calloc?
What is a nested formula?
Explain what is the difference between the expression '++a' and 'a++'?
#include
What is the purpose of main( ) in c language?
What are terms in math?
can anyone suggest some site name..where i can get some good data structure puzzles???
Why c is called a middle level language?