using switch statement in java write a menu driven prg to check and display weather a num input by the user is a composite number or not
Answers
Answered by
1
Answer:
Explanation:
bool isComposite(int n)
{
// Corner cases
if (n <= 1) return false;
if (n <= 3) return false;
// This is checked so that we can skip
// middle five numbers in below loop
if (n%2 == 0 || n%3 == 0) return true;
for (int i=5; i*i<=n; i=i+6)
if (n%i == 0 || n%(i+2) == 0)
return true;
else
return false;
}
// Driver Program to test above function
int main()
{
isComposite(11)? cout << " true\n": cout << " false\n";
isComposite(15)? cout << " true\n": cout << " false\n";
return 0;
}
Similar questions
Hindi,
5 months ago
Social Sciences,
5 months ago
Physics,
5 months ago
English,
11 months ago
Psychology,
11 months ago
Math,
1 year ago
Hindi,
1 year ago