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

1+2+1=4 1+2+3+2+1=9 1+2+3+4+3+2+1=16 but I just haven\'t figured out to make tha

ID: 3879830 • Letter: 1

Question

1+2+1=4

1+2+3+2+1=9

1+2+3+4+3+2+1=16

but I just haven't figured out to make that functional using recursive functions

PROBLEM 2: Below is a (trivial) C function which returns the square of its parameter (a non-negative integer): unsigned int square(unsigned int n) { return n*n Your job: write a function which also returns ' but with the following constraints: · You cannot use the multiplication operator … You cannot use the division operator/ You cannot have any loops You cannot add any additional parameters to the function Your function must be self-contained: no helper functions! . You cannot use any globals You cannot use any static variables . You cannot use any "bit twiddling" operations -- no shifts, etc. However . You can use recursion . You can use the '+' and operators.

Explanation / Answer

Main.c

#include <stdio.h>

unsigned int square(unsigned int n)
{

//if the number is 1 simply return 1
if(n==1)
return 1;
else //add the number and the number previous to it

//so that the number except the given number whose

// square is to be computed is added twice along with

//return value of recursive function call with parameter

//having the previous number(n-1)

return n+(n-1)+square(n-1);
}

/* To test the square function */

int main()
{
unsigned int res,in;
scanf("%u",&in);
res=square(in);
printf("Hello World: %u",res);

return 0;
}