Answers for "Summation of Natural Number Sequence with c and c++."

C++
0

Summation of Natural Number Sequence with c and c++.

#include<bits/stdc++.h>
using namespace std;
int main()
{    
  unsigned int a, b;    
  long long int sum = 0, n;    
  double s1;    
  cin >> a >> b;    
  n = (b-a) + 1;    
  sum = n * ((double)(a+b) / 2);    
  cout << sum << endl;        
  return 0;
}
Posted by: Guest on July-27-2021

Browse Popular Code Answers by Language