Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Sum All Numbers in a Range

const sumAll = arr => {
   let maxNumber = Math.max(...arr)
   let minNumber = Math.min(...arr)
   let numbersArray = []

   for(let i = minNumber; i <= maxNumber; i++){
     numbersArray.push(i)
   }
   return numbersArray.reduce((acc, cur) => acc + cur, 0)
}

sumAll([1, 4]);

// With love @kouqhar
Comment

sum range

>>> sum(range(4))  # 0 + 1 + 2 + 3
6
Comment

sum in range

//Java program to print the sum of numbers in a given rangeimport java.util.Scanner;public class sum_of_numbers_in_range{		public static void main(String[] args)	{		//scanner class declaration		Scanner sc = new Scanner(System.in);		//input from user		System.out.print("Enter starting number : ");						int start = sc.nextInt();		System.out.print("Enter ending number : ");						int end = sc.nextInt();		//declare a variable to store sum		int sum = 0;		//loop to add n natural numbers		for(int i = start ; i <= end ; i++)		sum=sum+i;		//display the sum		System.out.print("Sum of numbers in the range from "+start+" to "+end+" is "+sum);		//closing scanner class(not compulsory, but good practice)		sc.close();														}}
Comment

get sum of range

// 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 :: C++ OpenCV Face Recognition 
Cpp :: ue4 c++ string from fvector 
Cpp :: libraries required for gaming in c++ 
Cpp :: hpp files 
Cpp :: 28+152+28+38+114 
Cpp :: crtdbg c++ 
Cpp :: txt auslesen c++ 
Cpp :: Passing a string to a function 
Cpp :: how to writte comment in c++ 
Cpp :: Arduino C++ servomotor random moving 
Cpp :: check if number is positive or negative in cpp 
Cpp :: Pawri Meme codechef solution in c++ 
Cpp :: fabs in c++ example 
Cpp :: how to test if char in = to another in c++ 
Cpp :: binary algebra cpp 
Cpp :: c pointer syntax 
Cpp :: distructor of the node of the link list 
Cpp :: time optimisation c++ 
Cpp :: c++ language 
Cpp :: map update field elixir 
Cpp :: The iostream is the head er file which contains all the functions of program like cout, cin and etc. 
Cpp :: 1603. Design Parking System leetcode solution in c++ 
Cpp :: QMetaObject_invokeMethod 
Cpp :: multiply two arbitrary integers a and b (a greater than b) 
Cpp :: opencv read gif c++ 
Cpp :: print number with leading zeros 
Cpp :: c++ variables 
Cpp :: in c++ 
Cpp :: hello world cpp 
C :: remix icon cdn 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =