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 power of each element
Given an array of at least one integer, write a program to create a new array with elements equal to the power of each element in the original array raised to the index, ie Pi Aii
For this, write two functions that will be called in main function independently.
power
inputs: element Ai and index i
task: returns the value of element raised to index Aii
newElement
inputs: base address of new array P P current size of P variable k 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 AP; Base addresses of A and P
int n k; Lengths of arrays A and B
int pow; Return value from power function
Task of main function
P; th element A
for int j ; j n; j
k j; Current length of array B
pow powerAj j;
newElementP k pow;
k;
int powerint a int b
int pow a;
for int l ; l b; l
pow pow a;
returnpow;
void newElementint P int k int pow
Pk pow;
Registers Variables
$s A
$s n
$s P
$s k
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 P is:
Addresses Contents
I NEED MIPS CODE FOR THIS AS WELL AS THE C CODE.
LA is an unrecognized commandf in the mips we are using same with li
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