C Online Compiler
Example: Print Descending Series with While Loop in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Print Descending Series with While Loop #include <stdio.h> int main() { // Step 1: Initialize an integer variable 'i' with the starting value. int i = 5; // Step 2: Set the loop condition: continue as long as 'i' is greater than or equal to 1. while (i >= 1) { // Step 3: Print the current value of 'i' followed by a space. printf("%d ", i); // Step 4: Decrement 'i' by 1. This step is crucial to prevent an infinite loop. i--; } // Step 5: Print a newline character at the end. printf("\n"); return 0; }
Output
Clear
ADVERTISEMENTS