Calculate difference of two ranges given Write a method to compute the difference between two ranges. A range is defined by an integer low and an integer high. A - B (A “minus” B) is “everything in A that is not in B”.

This is an interview question and here is my code: 

void findDiff(int a1,int a2, int a3, int a4)
{
   cout&lt;&lt;"("&lt;&lt;a1&lt;&lt;","&lt;&lt;a2&lt;&lt;") - ("&lt;&lt;a3&lt;&lt;","&lt;&lt;a4&lt;&lt;") = \n";

   if(a1 &lt; a3) 
   {
         int end = (a2&lt;a3) ? a2: a3-1;
         for(int i=a1; i&lt;=end; i++) cout&lt;&lt;i&lt;&lt;"\t";
   }

   if(a4 &lt; a2) 
   {
         int start = (a1&gt;a4) ? a1 : (a4+1);
         for(int i=start; i&lt;=a2; i++) cout&lt;&lt;i&lt;&lt;"\t";
   }
   cout&lt;&lt;"\n";
}


Please look at the code and tell me if it correct and if I'm missing any case. Thanks a lot in advance :)
Make sure this is the signature they want. e.g. they do not expect the function to return vector, iterator or sthg. Also make sure they do not expect you to validate input. e.g. a1 &lt;= a2 etc... after that you can remove redundant conditionals, they are already present in the for loops. And you can replace ternary operators with std::min/max for a more idiomatic c++. otherwise I could not find any missed case or off-by-one bugs.

void findDiff(int a1,int a2, int a3, int a4)
{
   cout&lt;&lt;"("&lt;&lt;a1&lt;&lt;","&lt;&lt;a2&lt;&lt;") - ("&lt;&lt;a3&lt;&lt;","&lt;&lt;a4&lt;&lt;") = \n";

    for(int i=a1; i&lt;=std::min(a2, (a3-1)); i++) cout&lt;&lt;i&lt;&lt;"\t";

    for(int i=std::max(a1, (a4+1)); i&lt;=a2; i++) cout&lt;&lt;i&lt;&lt;"\t";

    cout&lt;&lt;"\n";
}