“soma no alcance” Respostas de código

Obtenha soma no alcance

# 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)))
Minion OuO

soma no alcance

//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();														}}
sree_007

Respostas semelhantes a “soma no alcance”

Perguntas semelhantes a “soma no alcance”

Mais respostas relacionadas para “soma no alcance” em Java

Procure respostas de código populares por idioma

Procurar outros idiomas de código