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


Please Help Members By Posting Answers For Below Questions

What is a union?

601


What is #ifdef ? What is its application?

638


Can we change the value of #define in c?

578


Does c have class?

604


Is c is a low level language?

555






What is use of pointer?

577


What is omp_num_threads?

569


How would you obtain the current time and difference between two times?

719


Differentiate between a structure and a union.

753


What is use of null pointer in c?

563


What are the output(s) for the following ? #include char *f() {char *s=malloc(8); strcpy(s,"goodbye")} main() { char *f(); printf("%c",*f()='A'); }

689


Explain what does it mean when a pointer is used in an if statement?

608


What is void c?

558


What are the advantages of using Unions?

638


Describe the difference between = and == symbols in c programming?

767