C Program to add two arrays into third array
Simple C Program to add two arrays into third array
Here we are going to add two arrays into third array. First we declare and define two arrays. Then we add these two array into third array. For example two arrays are arr1={3,2,5,7} and array second is arr2={7,11,2,9} then third array will be arr3={3,2,5,7,7,11,2,9}.
Here we are going to add two arrays into third array. First we declare and define two arrays. Then we add these two array into third array. For example two arrays are arr1={3,2,5,7} and array second is arr2={7,11,2,9} then third array will be arr3={3,2,5,7,7,11,2,9}.
#include<stdio.h> int main() { int arr1[]={2,12,4,23,87,6}; int arr2[]={12,32,1,8,56,8,9}; int arr3[20],i; int n1=sizeof(arr1)/sizeof(arr1[0]); int n2=sizeof(arr2)/sizeof(arr2[0]); for(i=0;i<n1+n2;i++) { if(i<=n1-1) arr3[i]=arr1[i]; else arr3[i]=arr2[i-n1]; } printf("Third array is \n"); for(i=0;i<n1+n2;i++) { printf("%d ",arr3[i]); } return 0; }