Quảng cáo
2 câu trả lời 170
2 năm trước
# Nhập số lượng phần tử trong dãy
n = int(input("Nhập số lượng phần tử trong dãy: "))
# Khởi tạo một biến để lưu trữ số nhỏ nhất, gán giá trị là giá trị đầu tiên nhập vào
min_number = int(input("Nhập số thứ 1: "))
# Nhập các số còn lại và so sánh để tìm số nhỏ nhất
for i in range(2, n + 1):
number = int(input(f"Nhập số thứ {i}: "))
if number < min_number:
min_number = number
# In số nhỏ nhất tìm được
print(f"Số nhỏ nhất trong dãy là: {min_number}")
2 năm trước
# Program to calculate the sum of even numbers in a range
# Get input from the user
n = int(input("Enter a number: "))
# Initialize a variable to store the sum
sum = 0
# Iterate through the range of numbers from 1 to n
for i in range(1, n+1):
# Check if the current number is even
if i % 2 == 0:
# If it is even, add it to the sum
sum += i
# Print the sum
print("The sum of even numbers from 1 to", n, "is", sum)
2.
# Program to calculate the sum of odd numbers in a range
# Get input from the user
n = int(input("Enter a number: "))
# Initialize a variable to store the sum
sum = 0
# Iterate through the range of numbers from 1 to n
for i in range(1, n+1):
# Check if the current number is odd
if i % 2 == 1:
# If it is odd, add it to the sum
sum += i
# Print the sum
print("The sum of odd numbers from 1 to", n, "is", sum)
3.
# Program to calculate the sum of the series S = 1 + 1/2 + 1/3 + ... + 1/n
# Get input from the user
n = int(input("Enter a number: "))
# Initialize a variable to store the sum
sum = 0
# Iterate through the range of numbers from 1 to n
for i in range(1, n+1):
# Add the current term to the sum
sum += 1 / i
# Print the sum
print("The sum of the series S = 1 + 1/2 + 1/3 + ... + 1/n for n =", n, "is", sum)
...Xem thêm
# Get input from the user
n = int(input("Enter a number: "))
# Initialize a variable to store the sum
sum = 0
# Iterate through the range of numbers from 1 to n
for i in range(1, n+1):
# Check if the current number is even
if i % 2 == 0:
# If it is even, add it to the sum
sum += i
# Print the sum
print("The sum of even numbers from 1 to", n, "is", sum)
2.
# Program to calculate the sum of odd numbers in a range
# Get input from the user
n = int(input("Enter a number: "))
# Initialize a variable to store the sum
sum = 0
# Iterate through the range of numbers from 1 to n
for i in range(1, n+1):
# Check if the current number is odd
if i % 2 == 1:
# If it is odd, add it to the sum
sum += i
# Print the sum
print("The sum of odd numbers from 1 to", n, "is", sum)
3.
# Program to calculate the sum of the series S = 1 + 1/2 + 1/3 + ... + 1/n
# Get input from the user
n = int(input("Enter a number: "))
# Initialize a variable to store the sum
sum = 0
# Iterate through the range of numbers from 1 to n
for i in range(1, n+1):
# Add the current term to the sum
sum += 1 / i
# Print the sum
print("The sum of the series S = 1 + 1/2 + 1/3 + ... + 1/n for n =", n, "is", sum)
Quảng cáo
Câu hỏi hot cùng chủ đề
-
Hỏi từ APP VIETJACK44928
-
Hỏi từ APP VIETJACK26915
Gửi báo cáo thành công!
