Hi everyone, I have an assignment for this week, what I dont understand about th
ID: 440889 • Letter: H
Question
Hi everyone, I have an assignment for this week, what I dont understand about this assignment is how functions and stack work! i tried to read the text book and other websites but I just couldnt get it right! i need help immediately!! Implement a MIPS assembly language program that defines "main", "readArray" and " sumBetween procedures. The readArray takes an array of integers and its length (int) as it parameters and read in integers from a user to fill the array. Note that if you change the content of the array in the readArray procedure, then the main procedure will also see the new content of the array. The sumBetween procedure takes an array of integers, its length, some minimum integer, and some maximum integer as its parameters and sums the elements that are between the minimum and the maximum, then returns it. The main needs to print the sum returned from the sumBetween procedure. If your program causes an infinite loop, press Control and 'C' keys at the same time to stop it. Name your source code file assignment6.s. C program that will ask a user to enter an integer 8 times and two integers for the maximum and the minimum, sum the elements that are between the minimum and the maximum, and also print the content of the array: //The readArray procedure reads integers from user input void readArray(int array[], int length) { int num, i = 0; while (i < length) { printf("Enter an integer: "); //read an integer from a user input and store it in num1 scanf("%d", &num); array[i] = num; i++; } return; } //The sumBetween procedure sums the elements //that are between the min and the max //(min and max are the parameter values) //Then it returns the sum. int sumBetween(int array[], int length, int min, int max) { int sum = 0; int i = 0; while (i < length) { if (min <= array[i]) { if (max >= array[i]) sum = sum+array[i]; } i++; } return sum; } // The main calls the readArray and the sumBetween // procedures void main() { int arraysize = 8; int numbers[arraysize]; int i, ans, num1, num2, min, max; readArray(numbers, arraysize); printf("Enter an integer for a bound "); scanf("%d", &num1); printf("Enter an integer for another bound "); scanf("%d", &num2); if (num1 < num2) { ans = sumBetween(numbers, arraysize, num1, num2); } else { ans = sumBetween(numbers, arraysize, num2, num1); } printf("The sum is: %d ", ans); i = 0; printf("The array contains the following: "); while (i < length) { printf("%d ", array[i]); i++; } return; } The following is a sample output (user input is in bold): Enter an integer: 1 Enter an integer: 2 Enter an integer: 3 Enter an integer: 4 Enter an integer: 5 Enter an integer: 6 Enter an integer: 7 Enter an integer: 8 Enter an integer for a bound: 6 Enter an integer for another bound: 3 The sum is: 18 The array contains the following: 1 2 3 4 5 6 7 8 -------------------------------------------------- Enter an integer: -51 Enter an integer: 12 Enter an integer: 5 Enter an integer: -7 Enter an integer: -11 Enter an integer: 52 Enter an integer: 21 Enter an integer: -32 Enter an integer for a bound: -7 Enter an integer for another bound: 30 The sum is: 31 The array contains the following: -51 12 5 -7 -11 52 21 -32 --------------------------------------------------Explanation / Answer
fn is not at all clear plz repost properly....
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.