+ 2
Program to find sum of n number using constructor.
9 Answers
+ 1
using function or class?
+ 1
what type of answer you want?
+ 1
wait
0
using function
0
long sum(int n, int a[])
{
long sum;
for(int i=0; i<n; i++)
{
sum+=a[i];
}
return sum;
}
0
do all
0
??
0
do all program
0
#include <iostream>
using namespace std;
int main() {
int n, arr[50];
cout<<"Enter the no of Numbers: ";
cin>>n;
cout<<"Enter the numbers: ";
for(int i=0; i<n; i++)
{
cin>>arr[i];
}
sum(n, arr);
return 0;
}