C Online Compiler
Example: Sum of Natural Numbers up to 100 (while loop) in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Sum of Natural Numbers up to 100 (while loop) #include <stdio.h> int main() { // Step 1: Declare and initialize variables int sum = 0; int i = 1; // Starting counter from 1 // Step 2: Use a while loop to iterate while (i <= 100) { // Step 3: Add the current number to the sum sum += i; // Step 4: Increment the counter i++; } // Step 5: Print the final sum printf("The sum of natural numbers up to 100 is: %d\n", sum); return 0; }
Output
Clear
ADVERTISEMENTS