Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Python :: how to backspace in python 
Python :: list.add in python 
Python :: arma-garch model python 
Python :: swapping 
Python :: how to input a picture into opencv raspberry pi 
Python :: 4D Array To DF 
Python :: django log queryset 
Python :: how to play audio in python using pygame 
Python :: python use getcontext 
Python :: python add hyphen to string 
Python :: make virtual environment python 
Python :: how does tkinter iconify() function work in python 
Python :: golang get started 
Python :: how to leave a function python 
Python :: Function in python with input method 
Python :: controlling the mouse with pynput 
Python :: csrf token django 
Python :: python child class call parent method 
Python :: target encoder sklearn example 
Python :: python collections to dictionary 
Python :: how to step or only print every two element of list python 
Python :: how to change an integer to a string in python permanently 
Python :: get table wikipedia 
Python :: remove punctuation 
Python :: input lstm 
Python :: check if a word is a noun python 
Python :: python remove second occurrence of character in string 
Python :: keras load model with custom objects 
Python :: tuple to string python 
Python :: guessing game python 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =