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
All technical questions
What are the types of type qualifiers in c?
Why is c known as a mother language?
Explain what is a 'locale'?
What is the difference between array and structure in c?
When should you use a type cast?
What is pointer to pointer in c language?
Is Exception handling possible in c language?
What is the easiest sorting method to use?
How to get string length of given string in c?
Write a program to use switch statement.
What is malloc return c?
Which is better malloc or calloc?
What are data structures in c and how to use them?
Is c still used?