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 are the various types of control structures in programming?
What is the use of the function in c?
What is hash table in c?
what is different between auto and local static? why should we use local static?
Why is c called c?
Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)
What should malloc() do?
What is the sizeof () operator?
What are the benefits of c language?
What are the disadvantages of a shell structure?
What is the difference between scanf and fscanf?
Explain bitwise shift operators?
What are nested functions in c?
How can I read and write comma-delimited text?
Explain what is page thrashing?