Search
 
SCRIPT & CODE EXAMPLE
 

CPP

get sum in range

# From user input, using lambda
# pass string directly to lambda
print((lambda s: sum(range(int(s[0]), int(s[1])+1)))(input().split()))
# or, convert string to list then pass into lambda
print((lambda s: sum(range(s[0], s[1]+1)))(list(map(int, input().split()))))
# input: 1 100
# output: 5050
# Or, simply, from variables
a, b = 1, 100
print(sum(range(a, b+1)))
Comment

get range sum

// get sum from x to y
// initialization of variables
int x = 1, y = 100, sum = 0;
// loop from x to y and add up the current index i
for(int i = x; i = y; i++) sum += i;
std::cout << sum;
Comment

PREVIOUS NEXT
Code Example
Cpp :: jquery datepicker default date not working 
Cpp :: error when using base class members 
Cpp :: find min and max in array c++ 
Cpp :: define for loop c++ 
Cpp :: what c++ library is arccos in 
Cpp :: Types of Triangles Based on Angles in c++ 
Cpp :: KL/wweiok#L['.[- 
Cpp :: how to measure cpp code performace 
Cpp :: youtube to facebook link converter 
Cpp :: check whether kth bit is 1 
Cpp :: how to install open cv2 in c++ on ubuntu 
Cpp :: destiny child 
Cpp :: cpp class access array member by different name 
Cpp :: loops in c++ with example 
Cpp :: convert c++ to c language 
Cpp :: file is good in c++ 
Cpp :: solve diamond inheritance c++ 
Cpp :: Temporary file using MSFT API in cpp 
Cpp :: c++ watch a variable 
Cpp :: c++ Unable to get CMake Tutorial example to compile 
Cpp :: c++ string to const char* 
Cpp :: JAJA 
Cpp :: xor in c++ 
Cpp :: c++ unordered set count 
Cpp :: c++ ignore_line 
Cpp :: c++ count inversions merge sort 
Cpp :: how to define a node in c++ 
Cpp :: c++ switch integer 
Cpp :: multilevel inheritance in c++ private method 
Cpp :: tic tac toe in cpp 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =