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 static variables in c?
What do you mean by a local block?
Write a simple code fragment that will check if a number is positive or negative.
write a program to find the given number is prime or not
What is the difference between single charater constant and string constant?
Explain what is wrong with this program statement? Void = 10;
What do you know about the use of bit field?
What are the primitive data types in c?
What is an example of structure?
How can I insert or delete a line (or record) in the middle of a file?
Why do we use int main?
What is logical error?
Write a C program in Fibonacci series.
How is a pointer variable declared?
What will be your course of action for a push operation?