C Programming Code Examples C > Arrays and Matrices Code Examples C Program to Compute the Sum of two One-Dimensional Arrays using Malloc C Program to Compute the Sum of two One-Dimensional Arrays using Malloc This C Program computes the sum of two one-dimensional arrays using malloc. The program allocates 2 one-dimentional arrays using malloc() call and then does the addition and stores the result into 3rd array. The 3rd array is also defined using malloc() call. #include <stdio.h> #include <malloc.h> #include <stdlib.h> void main() { int x, n; int *a, *b, *c; printf("How many Elements in each array...\n"); scanf("%d", &n); a = (int *)malloc(n * sizeof(int)); b = (int *)malloc(n * sizeof(int)); c = (int *)malloc(n * sizeof(int)); printf("Enter Elements of First List\n"); for (x = 0; x < n; x++) { scanf("%d", a + x); } printf("Enter Elements of Second List\n"); for (x = 0; x < n; x++) { scanf("%d", b + x); } for (x = 0; x < n; x++) { *(c + x) = *(a + x) + *(b + x); } printf("Resultant List is\n"); for (x = 0; x < n; x++) { printf("%d\n", *(c + x)); } }