Tuesday 9 December 2014

C program to find sum of two arrays

program to find sum of two arrays
#include<stdio.h>
main()
{
int i,n;
int a[5]={12,23,42,11,12},b[5]={65,34,22,1,22},c[5]={0};
n=sizeof(a)/sizeof(a[0]);
//a[5]={12,23,42,11,12}
//b[4]={65,34,22,1,22}
for(i=0;i<n;i++)
{
c[i]=a[i]+b[i];
printf("a[%d]=%d b[%d]=%d c[%d]=%d\n",i,a[i],i,b[i],i,c[i]);
}
printf("\n");
}
OutPut:
adan@madan-Lenovo-G570:~/madan$ ./a.out
a[0]=12 b[0]=65 c[0]=77
a[1]=23 b[1]=34 c[1]=57
a[2]=42 b[2]=22 c[2]=64
a[3]=11 b[3]=1 c[3]=12
a[4]=12 b[4]=22 c[4]=34