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

Hello, please see the below code in C. I am trying to compile it and it won\'t c

ID: 3750820 • Letter: H

Question

Hello, please see the below code in C. I am trying to compile it and it won't compile correctly due to the assignment of *xptr and the return statement in file 1. Without using the pow() function, can you please help me?

Thank you!!

File #1

#include <stdio.h>

int pow_xy(int *xptr, int y) {

int result;

while (y != 0) {

result *= *xptr;

y--;

}

*xptr = result;

return *xptr;

}

File #2

#include <stdio.h>
#include "file1.c"  

void test_p4() {
printf(" p4 ");
int numbers[5];
init_array(numbers, 5, 2);
int i;
for (i=0; i<5; i++)
printf("%d ", numbers[i]);
printf(" ");
}

int main() {

test_p4();

}

Explanation / Answer

This is the correct code made two changes the code works fine

#include <stdio.h>

int pow_xy(int *xptr, int y) {

int result = 1;

while (y != 0) {

result *= (*xptr);

y--;

}

*xptr = result;

return *xptr;

}

int main(){

int a = 5;

int b = 3;

int c = pow_xy(&a, b);

printf("%d", c);

}

Output is 125