Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Given an array of at least one integer, write a program to create a new array with elements equal to the exponent of each element
Given an array of at least one integer, write a program to create a new array with elements equal to the exponent of each element in the original array raised to the index, ie Bi Aii
For this, write two functions that will be called in main function independently.
exponent
inputs: element Ai and index i
task: returns the value of element raised to index Aii
append
inputs: base address of new array B B current size of B n and the new element Aii
task: add the new element at the end.
This function does not return any value void
Following is a sample C code to perform the required task. You may modify the code for the functions, but the task performed should not be changed.
int main
Variable Declaration
int A B; Base addresses of A and B
int n n; Lengths of arrays A and B
int exp; Return value from exponent function
Task of main function
B; th element A
for int j ; j n; j
n j; Current length of array B
exp exponentAj j;
appendB n exp;
n;
int exponentint x int y
int exp x;
for int j ; j y; j
exp exp x;
returnexp;
void appendint B int n int exp
Bn exp;
Registers Variables
$s A
$s n
$s B
$s n
Addresses Contents
$s A
$s A
$sn An
Example Test: If the values of $s through $s are initialized in the simulator as: Use the button under the Registers display to initialize register values for $s $s $s and the button under the Memory display to initialize the A array elements.
Registers Data
$s
$s
$s
$s
Addresses Contents
The resultant registers will be:
Registers Data
$s
$s
The resultant array B is:
Addresses Contents
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started