Answer on Question #47700, Programming, C++
Problem.
write a program to point the sum of six numbers with array and pointer
z
Solution.
Code
#include <iostream>
using namespace std;
float sum(float *arr) {
return arr[0] + arr[1] + arr[2] + arr[3] + arr[4] + arr[5];
}
int main() {
float arr[6];
// Input
for (int i = 0; i < 6; i++) {
cin >> arr[i];
}
// Output
cout << sum(arr);
return 0;
}Result
1 2 5 1 2 3
14
http://www.AssignmentExpert.com/</iostream>
Comments