Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that implements the follow ing functions int partial sum(int dat

ID: 3769506 • Letter: W

Question

Write a program that implements the follow ing functions int partial sum(int data[], int start, int end) void partial print(int data[], int start, int end) The function partial sum returns the sum of the array elements with indexes [start - end] and the function partial print prints the array elements with indexes [start - emi]. Create an array of 15 random numbers in the range [10 - 19]. Read the value of start and end from user and compute and print the partial sum and print the partial array. An example is given in figure 1. Random numbers you generate should be same as the ones in the figure. When the partial sum function is called with start = 1 and end = 4, the partial sum is 60 and the function returns 60. The array elements included in the partial sum is shown with an arrow in the figure. When partial print function is called with start = 1 and end = 4, it should print all array elements with index [1 -4]. Sample execution of the program is given below Enter starting and ending index 1 4 Partial Array Output: 1 17 2 14 3 10 4 19 Sum from data[l] to data [4] is 60

Explanation / Answer

#include<iostream>

using namespace std;

void partialprint(int arr[], int start, int end) {

for (int i=start; i<=end; i++) {

cout<<(i-start+1)<<" "<<arr[i]<<" ";

}

}

int partialsum(int arr[], int start, int end) {

int sum=0;

for (int i=start; i<=end; i++) {

sum+=arr[i];

}

return sum;

}

int main() {

int randomArray[15];

  

for (int i=0; i<15; i++) {

randomArray[i] = rand()%10 + 10;

}

  

int start, end;

cout<<"Enter starting and ending index ";

cin>>start>>end;

  

cout<<"Partial array output: ";

partialprint(randomArray, start, end);

cout<<"Sum of data["<<start<<"] to data["<<end<<"] is "<<partialsum(randomArray, start, end)<<" ";

  

  

cout<<" ";

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote