how to find the given number is prime or not?

Answer Posted / shweta

#include<stdio.h>
#include<conio.h>
void main()
{
int n,ctr=2,flag=0;
printf("enter the number to be checked\n");
scanf("%d",&n);
for(ctr=2;ctr<=n/2;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");
flag=0;
getch();
}

Is This Answer Correct ?    2 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

please explain every phase in the "SDLC" in the dotnet.

2173


What are reserved words with a programming language?

592


What is the difference between typedef struct and struct?

586


Is linux written in c?

593


What are c header files?

568






Write a program to generate random numbers in c?

651


Wt are the Buses in C Language

2741


What is the purpose of macro in C language?

655


What is the purpose of void in c?

609


Explain what is a 'locale'?

574


What does s c mean in text?

600


What is %lu in c?

671


Which is more efficient, a switch statement or an if else chain?

568


What is the difference between array and pointer in c?

569


How can you find the day of the week given the date?

607