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

Using C language and the DE2-115 Media Computer hardware configuration write a s

ID: 3825505 • Letter: U

Question

Using C language and the DE2-115 Media Computer hardware configuration write a subroutine that will return a value from an array that is selected by an input parameter. Use the stack to pass the parameter in, and to return the value of the result. Test your subroutine by writing a program that initializes the stack and calls the subroutine in a loop and passes it the value of the four slide switches SW3...SW0. Write the value that is returned from the subroutine to the HEX0 display. Use the following byte values to create the array: 0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x67, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71

Explanation / Answer

PROGRAM FOR WITH ARGUMENTS & WITH RETURN VALUE:

#include<stdio.h>

#include<string.h>

int function(int, int[], char[]);

int main()

{

      int i, a = 20;

      int arr[5] = {10,20,30,40,50};  

      char str[30] = ""fresh2refresh"";

      printf("    ***values before modification*** ");  

      printf("value of a is %d ",a);  

      for (i=0;i<5;i++)

      {

         // Accessing each variable

         printf("value of arr[%d] is %d ",i,arr[i]);  

      }

      printf("value of str is %s ",str);

      printf("     ***values after modification*** ");

      a= function(a, &arr[0], &str[0]);

      printf("value of a is %d ",a);  

      for (i=0;i<5;i++)

      {

         // Accessing each variable

         printf("value of arr[%d] is %d ",i,arr[i]);  

      }

      printf("value of str is %s ",str);

      return 0;

}

int function(int a, int *arr, char *str)

{

    int i;

    a = a+20;

    arr[0] = arr[0]+50;

    arr[1] = arr[1]+50;

    arr[2] = arr[2]+50;

    arr[3] = arr[3]+50;

    arr[4] = arr[4]+50;

    strcpy(str,""modified string"");

    return a;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote