Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Setting Iterations with the While Loop in C | While Loop
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
C Loops for Beginners

bookChallenge: Setting Iterations with the While Loop in C

A while loop in C repeatedly executes a block of code as long as a given condition is true. Here's a simple example to help you:

main.c

main.c

copy
123456
int i = 0; while (i < 3) { printf("Iteration %d\n", i); i++; }
Tarefa

Swipe to start coding

Write a function in C called powerCounter that takes two integer parameters a and b. The function should calculate the value of a raised to the power of b (that is, a^b) using a while loop. For each multiplication performed in the loop, increment a counter variable. The function must return the final value of the counter variable, which should be equal to b (the exponent).

  • Use a while loop to repeat the multiplication process exactly b times.
  • Start with a result variable set to 1.
  • For each iteration, multiply the result by a and increment the counter.
  • After the loop, return the counter variable.

Solução

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 2
single

single

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

Suggested prompts:

Can you show me a complete example of a while loop in C?

What happens if the condition in the while loop is never false?

Can you explain the difference between a while loop and a for loop in C?

close

bookChallenge: Setting Iterations with the While Loop in C

Deslize para mostrar o menu

A while loop in C repeatedly executes a block of code as long as a given condition is true. Here's a simple example to help you:

main.c

main.c

copy
123456
int i = 0; while (i < 3) { printf("Iteration %d\n", i); i++; }
Tarefa

Swipe to start coding

Write a function in C called powerCounter that takes two integer parameters a and b. The function should calculate the value of a raised to the power of b (that is, a^b) using a while loop. For each multiplication performed in the loop, increment a counter variable. The function must return the final value of the counter variable, which should be equal to b (the exponent).

  • Use a while loop to repeat the multiplication process exactly b times.
  • Start with a result variable set to 1.
  • For each iteration, multiply the result by a and increment the counter.
  • After the loop, return the counter variable.

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 2
single

single

some-alt