int main(int argc, char const *argv[]) { int i; Link* head = NULL; Link* end = head; char s[MAX_PRINT_LENGTH]; for (i = 1; i < argc; ++i) { end = add_link_num(end, strtod(argv[i], NULL)); if (!head) head = end; } printf("xs = {%s}\n", list_to_str(head, s, MAX_PRINT_LENGTH)); printf("sum = %4.3f\n", list_sum(head)); printf("product = %4.3f\n", list_product(head)); return 0; }
struct list *add_lists(struct list *a, struct list *b) { int sum_a = list_sum(a); int sum_b = list_sum(b); int sum_c = sum_a + sum_b; return int_to_list(sum_c); }
double list_sum(Link* head) { return head ? head->number + list_sum(head->next) : 0; }
static void list_sum_core(list_t* in, data_t owcr* d) { *d = list_sum(in, NULL); }