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
A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none
Which is not valid in C a) class aClass{public:int x;}; b) /* A comment */ c) char x=12;
How can I find the modification date and time of a file?
What is difference between arrays and pointers?
Write a factorial program using C.
How can I find out how much free space is available on disk?
what are non standard function in c
Write a simple code fragment that will check if a number is positive or negative.
What does a derived class inherit from a base class a) Only the Public members of the base class b) Only the Protected members of the base class c) Both the Public and the Protected members of the base class d) .c file
What are unions in c?
What is ambagious result in C? explain with an example.
What is equivalent to ++i+++j?
What is the right type to use for boolean values in c?
What is wrong with this program statement?
What is return type in c?