C Language while loop "Sum of 1 to 10 Numbers" program with output
#include <stdio.h>
int main() { int num = 1; // Initialize a variable to store the current number int sum = 0; // Initialize a variable to store the sum while (num <= 10) { // Loop while num is less than or equal to 10 sum += num; // Add the current number to the sum num++; // Increment the current number } printf("The sum of numbers from 1 to 10 is: %d\n", sum); return 0; }Output:
The sum of numbers from 1 to 10 is: 55
Comments
Post a Comment