Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Array With Powers of Two | Introduction to Arrays
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
C++ Arrays

bookChallenge: Array With Powers of Two

Task

Swipe to start coding

Write a function that fills an integer array with powers of two. The first element should be 1 (2⁰), the second 2 (2¹), the third 4 (2²), and so on.

  • Declare the array in main with a fixed size of 8.
  • Do not initialize the array when you declare it in main.
  • Complete the function fillPowersOfTwo so that it fills the array with powers of two, starting from 1.
  • Use a loop inside the function to fill the array.

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 3
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

close

bookChallenge: Array With Powers of Two

Swipe to show menu

Task

Swipe to start coding

Write a function that fills an integer array with powers of two. The first element should be 1 (2⁰), the second 2 (2¹), the third 4 (2²), and so on.

  • Declare the array in main with a fixed size of 8.
  • Do not initialize the array when you declare it in main.
  • Complete the function fillPowersOfTwo so that it fills the array with powers of two, starting from 1.
  • Use a loop inside the function to fill the array.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 3
single

single

some-alt