Sum of 1 to 'n' natural numbers

This is a for loop program in which we will find sum of 1 to 'n' natural numbers with the help of the C Programming language.




#include <stdio.h>

int main()
{
    long int i, n, sum;
    sum = 0;
    printf("Enter the last number for the sum of series from 1 to ");
    scanf("%ld", &n);

    for (i = 1; i < n; i++)
    {
        sum = sum + i;
    }

    printf("The sum from 1 to %ld = %ld",n, sum);

    return 0;
}

//......Coded by YASH ALAPURIA



#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post