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 clearly about execution of c program in detail,in which stage are the printf sacnf getting into exeecutable code

1899


Where does the name "C" come from, anyway?

844


how should functions be apportioned among source files?

847


Explain how can I convert a number to a string?

840


Explain how do you override a defined macro?

782


hi send me sample aptitude papers of cts?

1848


Which is best book for data structures in c?

792


Write a code to remove duplicates in a string.

811


Is c a great language, or what?

825


What are data types in c language?

777


Write a code of a general series where the next element is the sum of last k terms.

781


Explain what are reserved words?

826


What does node * mean?

938


Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.

1690


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

785