In the questions below you are asked to write a function/procedure in Scheme to
ID: 3888269 • Letter: I
Question
In the questions below you are asked to write a function/procedure in Scheme to implemert some behavior. To do so you may need to include auxillary functions/procedures. Include these with your answers. 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: (5 432 1) The empty list returns the empty list.Explanation / Answer
1.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester
{
class FindSum
{
public static int CaluculateSum(List<int> lstSum)
{
int sum=0;
foreach(var item in lstSum)
{
sum+=item;
}
return sum;
}
}
public class Program
{
public static void Main(string[] args)
{
int n;
List<int> lstIntegers=new List<int>();
Console.WriteLine("How many integers do you want to enter!");
n=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the integers");
for(int i=1;i<=n;i++)
{
lstIntegers.Add(Convert.ToInt32(Console.ReadLine()));
}
Console.WriteLine("The Sum is "+FindSum.CaluculateSum(lstIntegers));
}
}
}
Output:
2.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace Rextester
{
class FindSum
{
public static List<int> FindLength(List<int> lstSum)
{
List<int> lstLength=new List<int>();
int length=1;
foreach(var item in lstSum)
{
lstLength.Add(length);
length++;
}
return lstLength;
}
}
public class Program
{
public static void Main(string[] args)
{
int n;
List<int> lstIntegers=new List<int>();
lstIntegers.Add(10);
lstIntegers.Add(20);
lstIntegers.Add(30);
List<int> lstLength=FindSum.FindLength(lstIntegers);
int length=lstLength.Count();
Console.WriteLine("The Integer List Is ");
foreach(var item in lstIntegers)
{
Console.Write(item+" ");
}
Console.WriteLine(" The Length List Is ");
for(int i=length-1;i>=0;i--)
{
Console.Write(lstLength[i]+" ");
}
}
}
}
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.