how to find the given number is prime or not?

Answer Posted / shrikanth s.hallikhed

#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==1)
printf("the given number is prime\n");
else
printf("the given number is not prime\n");
getch();
}

Is This Answer Correct ?    3 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

In C language, a variable name cannot contain?

745


Explain pointers in c programming?

636


I have a varargs function which accepts a float parameter?

579


Can we initialize extern variable in c?

634


What are the data types present in c?

629






What is difference between structure and union in c programming?

569


Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?

603


Where in memory are my variables stored?

637


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

733


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

589


what is the diffrenet bettwen HTTP and internet protocol

1392


What is extern c used for?

571


What are the features of the c language?

648


What is getch c?

856


Are c and c++ the same?

627