Skip to main content

C Program to find the Sum of First n Natural numbers

Programming Languages

Welcome to coding world

C Program to find the Sum of First n Natural numbers

 Program to find the sum of first n natural numbers. We will see two C programs to calculate the sum of natural numbers. In the first C program we are using for loop for find the sum and in the second program we are doing the same using while loop.

Program to find sum of natural numbers using for loop

The user enters the value of n and the program calculate the sum of first n natural numbers using for loop.

 #include <stdio.h>

int main()

{

    int n, count, sum = 0;

 

    printf("Enter the value of n(positive integer): ");

    scanf("%d",&n);

 

    for(count=1; count <= n; count++)

    {

        sum = sum + count;

    }

 

    printf("Sum of first %d natural numbers is: %d",n, sum);

 

    return 0;

}

Output:

 

Enter the value of n(positive integer): 6

Sum of first 6 natural numbers is: 21

Popular posts from this blog

Good Morning Wishes

Aeza khan and Danish taimoor love story

Ayeza Khan bridal collection 2021 Ayeza Khan celebrate 10M on Instagram Danish Taimoor Danish Taimoor born on 16 February 1983 is a Pakistani actor and model.  He began his career in 2005 and seemed in "Mystery Series" (Do saal baad, Dracula); both episodes were directed by Imran khokhar and aired on Indus Vision. He is notable for his role in Urdu drama series' and telefilms in Pakistan.  Notable dramas include:  Haseena Moin's Meri Behen Maya  Mannchalay  Jab we Wed  Shert  Sari Bhool Humari thi  Aik Pal He made his film debut in Jalaibee in March 2015, directed by Yasir Jaswal

Ayeza Khan Bridal collection 2021

Pakistan Showbiz Ayeza khan celebrate 10M on Instagram Ayeza Khan & Danish Taimoor love story