Monday, 24 May 2021

Write a C program to find the sum of first 10 natural numbers

 Write a C program to find the sum of first 10 natural numbers





#include 
#include 
void main()
{
    int j, r, sum = 0;
    printf("Enter the range :");
    scanf("%d", &r);
    printf("The first %d natural number sum is :\n", r);

    for (j = 1; j <= r; j++)
    {
        sum = sum + j;
        printf("%d", j);
        while (j < r)
        {
            printf("+");
            break;
        }
    }
    printf(" = %d\n", sum);
}


Output:






Share:

Related Posts:

0 comments:

Post a Comment