AVERAGE


The source code for average.c may be downloaded. The purpose of this program is to demonstrate a procedure call which takes two parameters (called by value) and returns the average of the two values. The program then prints the average. All calculations are performed using integer arithmetic.


You type> cat average.c
int ave(int a, int b)
       // variablest a,b;
{
        return ((a+b)/2);
}
main()
{
        int x,y,s,s1;
        x = 6;
        y = 20;
        s = ave (x,y);
        printf("Average of %d and %d is %d\n",x,y,s);
        s1 = ave (x,s);
        printf("Average of %d and %d is %d\n",x,s,s1);
} 
you type> cc -o average average.c
you type> average
Average of 6 and 20 is 13
Average of 6 and 13 is 9


BACK to index page.