C Online Compiler
Example: Sum of Integers (For Loop) in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Sum of Integers (For Loop) #include <stdio.h> int main() { // Step 1: Declare and initialize variables int sum = 0; // Variable to store the sum, initialized to 0 int i; // Loop counter variable // Step 2: Use a for loop to iterate from 1 to 10 // The loop starts with i=1, continues as long as i is less than or equal to 10, // and increments i by 1 in each iteration. for (i = 1; i <= 10; i++) { sum += i; // Add the current value of i to sum } // Step 3: Print the final sum printf("The sum of numbers from 1 to 10 is: %d\n", sum); return 0; }
Output
Clear
ADVERTISEMENTS