C Online Compiler
Example: Sum of Integers (Formula) in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Sum of Integers (Formula) #include <stdio.h> int main() { // Step 1: Define the upper limit int n = 10; // The number up to which we want to sum // Step 2: Apply the arithmetic series formula // Sum = n * (n + 1) / 2 int sum = n * (n + 1) / 2; // Step 3: Print the calculated sum printf("The sum of numbers from 1 to %d using formula is: %d\n", n, sum); return 0; }
Output
Clear
ADVERTISEMENTS