Write a simple program sum of array in C++/C
#include <iostream>
using namespace std;
void SumofArray(int *arr, int n)
{
int sum = 0;
for (int i = 0; i < n; i++)
{
sum = sum + arr[i];
}
cout << "The Sum is : " << sum;
}
int main()
{
int arr[] = {1, 2, 3, 4};
int n = sizeof(arr) / sizeof(int);
SumofArray(arr, n);
}
Output is :
The Sum is : 10
The Sum is : 10
0 Comments