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
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