Complete the code to print numbers from 1 to 5 using a while loop.
#include <stdio.h> int main() { int i = 1; while ([1]) { printf("%d\n", i); i++; } return 0; }
The while loop continues as long as the condition is true. To print numbers 1 to 5, the condition should be i < 6.
Complete the code to sum numbers from 1 to 10 using a while loop.
#include <stdio.h> int main() { int sum = 0; int num = 1; while ([1]) { sum += num; num++; } printf("Sum is %d\n", sum); return 0; }
The loop should run while num is less than or equal to 10 to include 10 in the sum.
Fix the error in the while loop condition to avoid an infinite loop.
#include <stdio.h> int main() { int count = 5; while ([1]) { printf("%d\n", count); count--; } return 0; }
The loop should continue while count is greater than 0 to avoid infinite looping.
Fill both blanks to create a while loop that prints even numbers from 2 to 10.
#include <stdio.h> int main() { int num = [1]; while (num [2] 10) { printf("%d\n", num); num += 2; } return 0; }
Start from 2 and continue while num is less than or equal to 10 to print even numbers up to 10.
Fill all three blanks to create a while loop that counts down from 10 to 1 and prints each number.
#include <stdio.h> int main() { int count = [1]; while (count [2] 0) { printf("%d\n", [3]); count--; } return 0; }
Start counting from 10, continue while count is greater than 0, and print the current count.