write a program to read two one dimensional array and find the sum of elements of Array in C programming
Answers
C Program to Compute the Sum of two One-Dimensional Arrays using Malloc
This is a C Program to Compute the Sum of two One-Dimensional Arrays using Malloc
Problem Description
This program will allocate 2 one-dimentional arrays using malloc() call and then will do the addition and stores the result into 3rd array. The 3rd array is also defined using malloc() call.
Answer:
#include<iostream.h>
#include<conio.h>
void input1(int a[],int n)
{
cout<<"\nEnter elements of first array ";
for(int i=0;i<n;i++)
{
cin>>a[i];
}
}
void input2(int b[i],int n)
{
cout<<"\nEnter elements of second array ";
for(int i=0;i<n;i++)
{
cin>>a[i];
}
}
void add(int a[],int b[],int c[],int n)
{
for(int i=0;i<n;i++)
{
c[i]=a[i]+b[i];
cout<<c[i]<<endl;
}
}
void main()
{
clrscr();
int a[100],b[100],c[100],n;
cout<<"\n Enter size of array";
cin>>n;
input1(a,n);
input2(b,n);
add(a,b,c,n);
getch();
}