Answer to Question #330481 in C++ for milan

Question #330481

Write a program in C++ to read a number n and find out the sum of the integers from 1 to



then from 1 to 3, then 1 to 4, and so on and to display the sum of the integers from 1 to



n.



For example, from



1 to 2 = 1



1 to 3 = 3



1 to 4 = 6



1 to 5 = 10



1 to 6 = 18




1
Expert's answer
2022-04-20T03:44:58-0400



#include <iostream>
using namespace std;
//Summ out 1 -2 1-3 and out to display 1-n
int main() {
  int n;
  cout<<"Please enter n: ";
  cin>>n;
  int sum=1;
  for(unsigned i=2;i<=n;i++)
    {
      cout<<1<<"-"<<i<<" ="<<sum<<endl;
      sum+=i;
    }
  return  0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS