Passing arrays to functions

Thursday, November 13, 2014
/* 1604.c: Passing arrays to functions */
#include <stdio.h>

int AddThree(int list[]);

main()
{
    int sum, list[3];

    printf("Enter three integers separated by spaces:\n");
    scanf("%d%d%d", &list[0], &list[1], &list[2]);
    sum = AddThree(list);
    printf("The sum of the three integers is: %d\n", sum);

    return 0;
}
int AddThree(int list[])
{
    int i;
    int result = 0;

    for (i=0; i<3; i++)
        result += list[i];
    return result;
}

Copyright @ 2015 Tron!

Labels