Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
}
Source by www.urionlinejudge.com.br #
 
PREVIOUS NEXT
Tagged: #Summation #Natural #Number #Sequence
ADD COMMENT
Topic
Name
6+2 =