C Online Compiler
Example: Sum of Natural Numbers up to 100 (Formula) in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Sum of Natural Numbers up to 100 (Formula) #include <stdio.h> int main() { // Step 1: Define the upper limit (n) int n = 100; // Step 2: Calculate the sum using the formula int sum = n * (n + 1) / 2; // Step 3: Print the final sum printf("The sum of natural numbers up to 100 is: %d\n", sum); return 0; }
Output
Clear
ADVERTISEMENTS