Write the following program in c Each function in your progr
Write the following program in c++: Each function in your program should have a header comment as well. Describe its purpose, the parameters and the return value (if any). Use a format similar to: // Function name:
// Purpose:
// Parameters:
// Return value
(1) A composite number is an integer that has at least one divisor other than one or the number itself. Any integer greater than one that is not a prime number is a composite number. Write a function named is_composite that takes one positive integer number as argument and returns a boolean variable which is true if the number is a composite number and return false otherwise. Use this function is_composite in your main( ) function to print all composite numbers in the range of 5 and 155.
Solution
code:
#include <iostream> // std:s:cin, std::cout
#include <fstream> // std::ifstream
#include <map>
using namespace std;
bool is_composite(int n)
{
int i=2;
while(i<n/2)
{
if(n%i==0)
return true;
i++;
}
return false;
}
int main () {
int i=5;
while(i<=155)
{
if(is_composite(i))
cout<<i<<\" \";
i++;
}
return 0;
}
