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

Bollywood actor Dharmendra has passed away at the age of 89

Legendary Bollywood actor Dharmendra has passed away at the age of 89.  R. I. P The 'He-Man' of Indian cinema, known for his iconic roles in films like 'Sholay', 'Seeta Aur Geeta', and 'Dharam Veer', breathed his last on November 24, 2025, in Mumbai. Dharmendra's career spanned over six decades, with more than 300 films to his credit. He was a recipient of the Filmfare Lifetime Achievement Award and the Padma Bhushan, among other accolades. His family, friends, and fans are mourning his loss, remembering him as a kind soul and an unforgettable icon of Indian cinema. 

Good Morning Wishes

Jobs in Lahore June 2026 | Lahore Jobs 2026 | Latest jobs in Lahore

Job available for Lahore residence. Great opportunity for females. Comment msg for further details. click on link to apply job for freshers in Lahore:  Apply here Job Details 1: Receptionist Full job description Job opportunity join us as Branch Receptionist staff. Office base job and permanent job opportunity. Opportunity to join company official branch Receptionist staff. Responsibilities: 1-Office work 2-Strong command of Microsoft Office 3- Strong communication Skills 4- Typing speed 3.7+ 5- Strong web browsing skills Rewards: 1-Basic Salary 52000 2- Fuel Allowance 3- Medical Facility 4- Insurance Cover Working place is to good for male and females this is professional Branch Receptionist Staff Job Types: Full-time, Fresher Pay: Rs43,500.00 - Rs55,200.00 per month Ability to commute/relocate: Lahore: Reliably commute or planning to relocate before starting work (Preferred) Education: Bachelor's (Preferred) Work Location: In person Click here to apply now Job Details 2: Job Deta...