About Lesson
Calculate the Sum of N Numbers using a While Loop.
#include <stdio.h>
int main() {
int N, sum = 0, i = 1;// Taking input for N
printf(“Enter a positive integer N: “);
scanf(“%d”, &N);// Calculating the sum of numbers from 1 to N using a while loop
while (i <= N) {
sum += i;
i++;
}printf(“Sum of numbers from 1 to %d: %dn”, N, sum);
return 0;
}