Section 9.5: Subroutines (Frame 3)                     [prev][home][next]

The following C program has a main section and one function, called monus. Monus is a simplified form of subtraction that does not return negative numbers if the first argument is smaller than the second. In that case, it returns 0.

int monus(int a, int b)
{
     int result;
     if (a >= b)
          result = a-b;
     else
          result = 0;
     return result;
}

int main()
{
     int x = 8;
     int y = 5;
     int answer = monus(x, y);
     print(answer);
}