C Online Compiler
Example: Sum of Numbers in a Given Range in C using Function
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Sum of Numbers in a Given Range in C using Function #include <stdio.h> // Function to make sum of given range number int sum_of_range(int range_start, int range_end) { int sum = 0; // Use a loop from the start range to the end range to get the values & make the sum of each value while (range_start <= range_end) { sum += range_start; range_start++; } return sum; } // It's the main function of the program int main() { int range_start, range_end, sum = 0; // Step-1 Take input from the User printf("Start Range: "); scanf("%d", &range_start); printf("End Range: "); scanf("%d", &range_end); // Step-3 Call the sum_of_range() function to get the sum of the input range number printf("Total Sum: %d", sum_of_range(range_start, range_end)); return 0; }
-2 6
Output
Clear
ADVERTISEMENTS