C Program to sum of n natural numbers using do while
Program
#include<stdio.h>
void main()
{
int n, count, sum;
sum = 0;
count = 1;
printf("Enter the value of n\t");
scanf("%d", &n);
do
{
sum += count;
count++;
} while(count <= n);
printf("Sum of first %d natural numbers is: %d\n", n, sum);
}
Output
$ gcc sum-of-n-natural-numbers-using-do-while.c
$ ./a.out
Enter the value of n 10
Sum of first 10 natural numbers is: 55