C Online Compiler
Example: Sum of Numbers in a Given Range in C using While loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Sum of Numbers in a Given Range in C using While loop #include <stdio.h> // 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-2 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++; } // Step-3 Final output of the program printf("Total Sum: %d", sum); return 0; }
10 15
Output
Clear
ADVERTISEMENTS