Question: This is to be written in C programming. Please do not use pointers/arrays. This exercise focuses on iteration loops. 4 Exercise 3: Functions on powers

This is to be written in C programming. Please do not use pointers/arrays. This exercise focuses on iteration loops.

4 Exercise 3: Functions on powers of 2

TODO: Define and test a function called powers_of_2 that takes an integer n and prints the first n+1 powers of 22 (that is, 20,21,22,23,,2n20,21,22,23,,2n).

The output below demonstrates this functionality with three calls to powers_of_two.

powers_of_two(0) called to print 1 terms: 1 powers_of_two(4) called to print 5 terms: 1 2 4 8 16 powers_of_two(10) called to print 11 terms: 1 2 4 8 16 32 64 128 256 512 1024 

TODO: Define and test a function called sum_powers_of_2 that takes an integer n and returns the sum of the first n+1 powers of 22 :

i=0n2ii=0n2i

That is, it should return: 20+21+22+23++2n20+21+22+23++2n.

The output below demonstrates this functionality with three calls to sum_powers_of_two.

sum_powers_of_two(0) called to sum 1 terms: 1 sum_powers_of_two(4) called to sum 5 terms: 31 sum_powers_of_two(10) called to sum 11 terms: 2047 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!