w3resource

C Programming Exercises, Practice, Solution : While Loop

C While Loop [11 exercises with solution]

[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]

1. Write a C program to print numbers from 0 to 10 and 10 to 0 using two while loops.

Click me to see the solution

2. Write a C program that prompts the user to input a series of integers until the user stops entering 0 using a while loop. Calculate and print the sum of all the positive integers entered.

Click me to see the solution

3. Write a C program that calculates the product of numbers from 1 to 5 using a while loop.

Click me to see the solution

4. Write a C program that prompts the user to input a series of numbers until they input a duplicate number. Use a while loop to check for duplicates.

Click me to see the solution

5. Write a C program that generates a random number between 1 and 20 and asks the user to guess it. Use a while loop to give the user multiple chances until they guess the correct number.

Click me to see the solution

6. Write a C program that prompts the user to enter a positive integer. It then calculates and prints the factorial of that number using a while loop.

Click me to see the solution

7. Write a C program that prompts the user to input a username. Use a while loop to keep asking for a username until a valid one is entered (e.g., at least 8 characters long).

Click me to see the solution

8. Write a C program that calculates and prints the sum of cubes of even numbers up to a specified limit (e.g., 20) using a while loop.

Click me to see the solution

9. Write a C program that implements a program to check if a given number is a palindrome using a while loop.

Click me to see the solution

10. Write a C program to find and print the first 10 Fibonacci numbers using a while loop.

Click me to see the solution

11. Write a C program that prompts the user to enter a positive integer. Use a while loop to print the multiplication table for that number up to 10.

Click me to see the solution

C Programming Code Editor:

More to Come !

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Follow us on Facebook and Twitter for latest update.