Categories: Uncategorized

C++ Program to calculate the sum of n natural numbers using do while loop


Code :

Result :

Program to calculate the sum of n natural numbers using do while loop
//Program to calculate the sum of n natural numbers using do while loop formula if you want sum = number * (1 + number)/2

#include<iostream>

using namespace std;

main()

{

 int number, sum = 0, i= 1;

 

 cout << "Enter the nth Number of Natural Number" << endl;

 cin >> number;

 

 do

 {    

     

  sum = sum + i; 

  i++; 

 }

 while(i <= number);

 

 cout << "the sum upto "<< number << "th Natural Number is : " << sum;

 

 return 0;

}
reecry

Recent Posts

Insta360 – Videos keep exporting backwards | Wrong side render in insta360

https://youtu.be/0RRUOIvmuWA I realized that I had my camera set up incorrectly, so when I upload…

6 months ago

Make Animated progress step bar using Figma

https://youtu.be/C3oFfV20K_c Make Animated progress step bar using Figma

7 months ago

How to Hide All Grids in Figma

https://youtu.be/o3pSH_oRzko How to Hide All Grids in Figma

7 months ago

How to Create Responsive Tool tip in figma

https://youtu.be/hdSUylKSsho How to Create Responsive Tool tip in Figma

7 months ago

Pixel Grid not visible in figma | How to Turn on figma Pixel Grid

https://youtu.be/AEiH7dSDhKo Having issue in figma pixel grid? learn how to show/ hide figma pixel grid…

7 months ago

Fix External Monitor Lag on Mac OS Ventura

https://youtu.be/iilYzHg9LwQ There are some issues going on in ventura OS its still in development phase…

1 year ago