MC logo
Functional Average
[^] CSc 220 Home
[Introduction] [Boolean and Control] [Functions] [Arrays and Pointers] [Dynamic Arrays] [Array Errors] [Command Array] [Standard Containers] [Structs and Classes] [Automatic Pointer] [Multi-File Programs] [Copying Objects] [Templates] [Inheritance] [Plain C I/O] [Type Odds And Ends] [Plain C Strings] [File I/O]
[Functional Average] [Functional Average II] [Functional Average III] [Default Parameters] [Function Overloading] [Reference Parameters] [Constant References] [Namespaces] [Namespaces I] [Using Namespaces]
#include <iostream>
using namespace std;

double av(int n1, int n2, int n3)
        double sum;

        sum = n1 + n2 + n3;
        return sum / 3.0;
int main(void)
        int n1, n2, n3;

        cout << "Enter: ";
        cin >> n1 >> n2 >> n3;

        cout << "The average of " << n1 << " " << n2 << " " << n3 
             << " is " << av(n1, n2, n3) << endl;

        return 0;

Plain C does not have have classes; top-level functions like this are all there is. They are called without a class or object name. C++ follows.

Main is just the function that the O/S calls to get the program started.

Parameters are passed by value, but we will show some variations later.