Write a program that implements the following functions The function partial sum
ID: 3555512 • Letter: W
Question
Write a program that implements the following functions 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 - 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. Figure1: Example 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 6O and the function returns 6O. The array elements included in the partial sum is shown with an arrow in the figure. When partial print function is called with star t = 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: 17 14 10 19 Sum from data[1] to data[4] is 60Explanation / Answer
#include <stdio.h>
#include <string.h>
int partialsum(int data[], int start, int end);
void partialprint(int data[], int start, int end);
main() {
int data[] = {11, 17, 14, 10, 19, 14, 18, 18, 12, 14, 15, 11, 7, 11};
int start, end;
printf("Enter starting and ending index ");
scanf("%d", &start);
scanf("%d", &end);
printf("%d, %d ", start, end);
partialprint(data, start, end);
int partial_sum = partialsum(data, start, end);
printf("Sum from data[%d] to data[%d] is %d ", start, end, partial_sum);
}
int partialsum(int data[], int start, int end) {
int sum = 0;
while(start <= end) {
sum += data[start];
start++;
}
return sum;
}
void partialprint(int data[], int start, int end) {
printf("Partial Array Output ");
while(start <= end) {
printf("%d %d ", start, data[start]);
start++;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.