Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Write a program to find whether the given number is prime or
not?

Answer Posted / naman patidar

we can reduce no of iterations by changing the condition
(i<=n/2) with (i<=sqrt(n))..
This is a rule that if a number is not dividable by any no
(except 1)less than equal to the sqr root of it then the no
is prime.

int n ; // any no, user input.
int i ;
for(i=2; i<=sqrt(n); i++ )
{
if(n%i==0)
{
printf("not prime");
break;
}
}
if(i > sqrt(n)) // you can use a flag as well here
{
printf("prime no");
}

Is This Answer Correct ?    7 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What type of function is main ()?

1086


What is structure pointer in c?

1091


Explain what is the difference between #include and #include 'file' ?

1079


List the difference between a While & Do While loops?

1152


Describe explain how arrays can be passed to a user defined function

1164


What is the argument of a function in c?

1101


write a program for the normal snake games find in most of the mobiles.

2307


Why is it important to memset a variable, immediately after allocating memory to it ?

2133


Why do we use stdio h and conio h?

1134


differentiate built-in functions and user – defined functions.

1148


How do you list files in a directory?

1210


What is chain pointer in c?

1114


How is null defined in c?

1205


Why & is used in scanf in c?

1146


Is it possible to use curly brackets ({}) to enclose single line code in c program?

1372