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

Explain what are multibyte characters?

1257


Is python a c language?

1057


What will the preprocessor do for a program?

1120


Difference between macros and inline functions? Can a function be forced as inline?

1352


What are types of preprocessor in c?

1116


what is bit rate & baud rate? plz give wave forms

2030


Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)

1326


How do I round numbers?

1057


What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.

4340


Explain high-order and low-order bytes.

1172


Explain what is #line used for?

1127


How important is structure in life?

1153


Explain what is meant by high-order and low-order bytes?

1095


Can a file other than a .h file be included with #include?

1225


Can you please explain the difference between exit() and _exit() function?

1087