Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the following program in c++: Each function in your program should have a

ID: 3928185 • Letter: W

Question

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.

Explanation / Answer

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;
}