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

1. (100 pts) Write a program that implements the following functions int partial

ID: 3760488 • Letter: 1

Question

1. (100 pts) Write a program that implements the following functions int partialsum(int data[), int start, int end) void partialprint(int data[], int start, int end) The function partialsum returns the sum of the array elements with indexes [start - end] and the function partialprint prints the array elements with indexes [start ? end]. 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. Figure 1: Example An example is given in figure 1. Random numbers you generate should be same as the ones in the figure. When the partialsum 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 partialprint 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 14 Partial Array Output: 1 17 2 14 3 10 4 19 Sum from data[1] to data[4] is 60

Explanation / Answer

#include <stdlib.h>

int partialsum(int data[], int start, int end)
{
int i, sum = 0;

for (i = start; i <= end; i++)
sum += data[i];

return sum;
}

void partialprint(int data[], int start, int end)
{
int i;

printf("Partial Array Output: ");

for (i = start; i <= end; i++)
printf("%d %d ", i, data[i]);
}

int main()
{
int data[15], i, start, end;

for (i = 0; i < 15; i++)
data[i] = (rand() % 10) + 10;

printf("Enter starting and ending index ");
scanf("%d %d", &start, &end);
partialprint(data, start, end);
printf("Sum from data [%d] to data[%d] is %d ", start, end, partialsum(data, start, end));

system("pause");
return 0;
}