a C++ program to calculate the sum of 10 natural numbers
Answers
Answered by
3
Answer:
Coding:
#include <iostream>
using namespace std;
int main()
{
int i,sum=0;
cout << "\n\n Find the first 10 natural numbers:\n";
cout << "---------------------------------------\n";
cout << " The natural numbers are: \n";
for (i = 1; i <= 10; i++)
{
cout << i << " ";
sum=sum+i;
}
cout << "\n The sum of first 10 natural numbers: "<<sum << endl;
}
Output:
Find the first 10 natural numbers:
---------------------------------------
The natural numbers are:
1 2 3 4 5 6 7 8 9 10
The sum of first 10 natural numbers: 55
Similar questions
Political Science,
4 months ago
Math,
4 months ago
English,
4 months ago
Science,
8 months ago
Social Sciences,
8 months ago
Biology,
11 months ago
Science,
11 months ago
Geography,
11 months ago