how to find the given number is prime or not?

Answer Posted / rajamanickam.m

#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 ?    3 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is difference between structure and union in c programming?

753


What is 2 d array in c?

726


what are the different storage classes in c?

844


What is string concatenation in c?

750


What is the purpose of ftell?

798






What are Macros? What are its advantages and disadvantages?

844


what is a function method?give example?

2094


Why we write conio h in c?

745


What is the benefit of using #define to declare a constant?

820


What functions are used in dynamic memory allocation in c?

767


Why can't I perform arithmetic on a void* pointer?

812


What is an operator?

826


in case any function return float value we must declare a) the function must be declared as 'float' in main() as well b) the function automatically returned float values c) function before declared 'float' keyword d) all the above

788


How do I determine whether a character is numeric, alphabetic, and so on?

836


Can you define which header file to include at compile time?

774