You copy the url and paste it in the box on the website
Answer:
The solution is implemented using C++
int getRowTotal(int a[][5], int row) {
int sum = 0;
for(int i =0;i<5;i++)
{
sum += a[row][i];
}
return sum;
}
Explanation:
This defines the getRow function and the parameters are arr (the 2 d array) and row and integer variable
int getRowTotal(int arr[][5], int row) {
This defines and initializes sum to 0
int sum = 0;
This iterates through the row and adds the row items
<em> for(int i =0;i<5;i++) {
</em>
<em> sum += arr[row][i];
</em>
<em> }
</em>
This returns the calculated sum
return sum;
}
Answer:
The template is given in C++
Explanation:
#include <iostream>
using namespace std;
//Template function that returns total of all values entered by user
template <class T>
T total (int n)
{
int i;
//Initializing variables
T sum = 0, value;
//Prompting user
cout << "\n Enter " << n << " values: \t ";
//Iterate till user enters n values
for(i=1; i<=n; i++)
{
//Reading a value
cin >> value;
//Accumulating sum
sum = sum + value;
}
//Return sum
return sum;
}
//Main function
int main()
{
int n;
//Reading n value
cout << "\n Enter number of values to process: ";
cin >> n;
//Calling function for integers and printing result
cout << "\n\n Total : " << total<int>(n);
cout << "\n\n";
//Function call for doubles and printing results
cout << "\n\n Total : " << total<double>(n);
cout << "\n\n";
return 0;
}