186k views
1 vote
Realizati un program care calculeaza si afiseaza suma tuturor numerelor divizibile cu x si y

cuprinse intre a si b, unde x, y, a, b sunt numere naturale citite de la tastatura, a

1 Answer

0 votes

Answer:

Here's one way you could write the program in Python: x = int(input("Enter x: "))

y = int(input("Enter y: "))

a = int(input("Enter a: "))

b = int(input("Enter b: "))

sum = 0

for i in range(a, b+1):

if i % x == 0 and i % y == 0:

sum += i

print("The sum of all numbers divisible by", x, "and", y, "between", a, "and", b, "is", sum)

This program takes input for x, y, a, and b, then uses a for loop to iterate through the range of numbers from a to b, inclusive. For each number in the range, it checks if it is divisible by both x and y using the modulus operator (%). If a number is divisible by both x and y, it is added to the sum. Finally, the program prints the final sum.

User Oleg Novosad
by
6.8k points