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

Sales and Marketing jobs in UAE | Jobs in dubai 2026 | latest Gulf jobs 2026

   Mobile Number: 0553390204    WhatsApp Number: +971553390204                                                                          

C++ Program to Display Number (Entered by the User)

Programming Languages Welcome to coding world   Write a C++ Program to Display Number (Entered by the User). Here’s simple Program to Print Number (Entered by the User) in C++ Programming Language. This program asks user to enter a number. When user enters an integer, it is stored in variable number using cin. Then it is displayed in the screen using cout. Here is source code of the C++ Program to Display Number (Entered by the User). The C++ program is successfully compiled and run(on Codeblocks) on a Windows system. The program output is also shown in below.   SOURCE CODE : /*   C++ Program to Display Number (Entered by the User)   */   #include <iostream> using namespace std;   int main() {     int number;       cout << "Enter an integer :: ";     cin >> number;       cout << "\nThe Number entered is :: " << number...

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.