menu search
brightness_auto
more_vert
Write a C++ program to find sum of first 100 natural numbers?
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike

1 Answer

more_vert
 
verified
Best answer
#include <iostream>

using namespace std;

int main() {
 int sum = 0;
 
 // loop through the first 100 natural numbers and add them to sum
 for (int i = 1; i <= 100; i++) {
 sum += i;
 }
 
 // print the sum
 cout << "The sum of the first 100 natural numbers is " << sum << endl;
 
 return 0;
}


This program declares an integer variable calledsum and initializes it to 0. It then uses a for loop to iterate through the first 100 natural numbers (i.e., 1 to 100), adding each number tosum. Finally, it prints out the value ofsum using thecout statement.

thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike

Related questions

thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike
0 answers
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 1 like thumb_down_off_alt 0 dislike
1 answer
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
1 answer

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

648 users

...