#include
void addLists(const int list1[], int size1, const int list2[], int size2, int result[]) { int i; if (size1 == size2) { for(i=0; i<size1; i++) { result[i] = list1[i] + list2[i]; } } }
int main(){ int first[10] = {1,2,3,4,5,6,7,8,9,10}; int second[10] = {1,2,3,4,5,6,7,8,9,10}; int result[10]; addLists(first, 10, second, 10, result); int i; for(i=0; i<10; i++) { printf("%d ",result[i]); } return 0; }
|
def addLists(list1, list2): """ Add corresponding items in two lists """ result = [] if len(list1) == len(list2): for num in range(1, len(list1)): result.append(list1[num] + list2[num]) return result
first = [1,2,3,4,5,6,7,8,9,10]
|