In the questions below you are asked to write a function/procedure in Scheme to
ID: 3887978 • Letter: I
Question
In the questions below you are asked to write a function/procedure in Scheme to implement me behavior. To do so you may need to include auxillary functions/procedures. Include these with your answers. so You may only use Scheme constructs and the EOPL extensions that have been presented in class. Put the answers to these questions in a single file. Tar or zip the file and submit the tar file to the submission system. Put a comment header in the file with your name, course number, and date. 1. (10 points) Given a list of integers, write a function that returns the sum of these inte- gers. We define the sum of the empty list to be 0 (zero). length (1st) down to 1. For example Given: (10 20 30 40 50) 2. (10 points) Given a list of integers 1st, write a function that returns a list with entries Return: (5432 1) The empty list returns the empty list.Explanation / Answer
1) /* C Program to find sum of elements in a given array */
#include <stdio.h>
// C program to return sum of elements in an array of size n
int sum(int arr[], int n)
{
int sum = 0; // initialize sum
int i;
// Iterate through all elements and add them to sum
for (i = 0; i < n; i++)
sum += arr[i];
return sum;
}
int main()
{
int arr[] = {12,3,4,15};
int n = sizeof(arr)/sizeof(arr[0]);
printf("Sum of given array is %d", sum(arr, n));
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.