C Program To Find Sum Of Natural Numbers Using (do---while) Loop

C Program To Find Sum Of Natural Numbers Using (do---while) Loop

Code
// WAP to find sum of natural numbers using (do---while) loop...

#include <stdio.h>

int main()
{

    int num, sum = 0, i = 1;
    printf("Enter A Number:\n");
    scanf("%d", &num);

    do
    {
        sum += i;
        i++;
    }

    while (i <= num);

    printf("Sum of natural number is\n%d", sum);
    return 0;
}
Output
Enter A Number:
100
Sum of natural number is
5050

Post a Comment