Thursday, 16 November 2017

C Program to Find the Sum of First N Natural Numbers


Code:

#include   stdio.h

void main()
{
    int i, num, sum = 0;

    printf("Enter an integer number \n");
    scanf ("%d", &num);
    for (i = 1; i <= num; i++)
    {
        sum = sum + i;
    }
    printf ("Sum of first %d natural numbers = %d\n", num, sum);
}


Output:

Enter an integer number
1300
Sum of first 1300 natural numbers = 845650


More C Programs:













100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...