Hướng dẫn what is armstrong number in python using function? - số armstrong trong python sử dụng hàm là gì?

Trong ví dụ này, bạn sẽ học cách kiểm tra xem một số nguyên chữ N có phải là số Armstrong hay không.

Để hiểu ví dụ này, bạn nên có kiến ​​thức về các chủ đề lập trình Python sau:

  • Python nếu ... tuyên bố khác
  • Python trong khi vòng lặp

Một số nguyên dương được gọi là số lượng đơn đặt hàng n nếu

abcd... = an + bn + cn + dn + ...

Trong trường hợp số lượng 3 chữ số của Armstrong, tổng khối của mỗi chữ số bằng chính với số lượng. Ví dụ:

153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.

Mã nguồn: Kiểm tra số Armstrong [cho 3 chữ số]

# Python program to check if the number is an Armstrong number or not

# take input from the user
num = int[input["Enter a number: "]]

# initialize sum
sum = 0

# find the sum of the cube of each digit
temp = num
while temp > 0:
   digit = temp % 10
   sum += digit ** 3
   temp //= 10

# display the result
if num == sum:
   print[num,"is an Armstrong number"]
else:
   print[num,"is not an Armstrong number"]

Đầu ra 1

Enter a number: 663
663 is not an Armstrong number

Đầu ra 2

Enter a number: 407
407 is an Armstrong number

Ở đây, chúng tôi yêu cầu người dùng cho một số và kiểm tra xem đó có phải là số Armstrong không.

Chúng ta cần tính toán tổng của khối lập phương của mỗi chữ số. Vì vậy, chúng tôi khởi tạo tổng thành 0 và lấy từng số chữ số bằng cách sử dụng toán tử mô đun %. Phần còn lại của một số khi nó được chia cho 10 là chữ số cuối cùng của số đó. Chúng tôi lấy các khối bằng cách sử dụng toán tử số mũ.

Cuối cùng, chúng tôi so sánh tổng với số gốc và kết luận rằng đó là số Armstrong nếu chúng bằng nhau.

Mã nguồn: Kiểm tra số lượng n chữ số của Armstrong

num = 1634

# Changed num variable to string, 
# and calculated the length [number of digits]
order = len[str[num]]

# initialize sum
sum = 0

# find the sum of the cube of each digit
temp = num
while temp > 0:
   digit = temp % 10
   sum += digit ** order
   temp //= 10

# display the result
if num == sum:
   print[num,"is an Armstrong number"]
else:
   print[num,"is not an Armstrong number"]

Bạn có thể thay đổi giá trị của num trong mã nguồn và chạy lại để kiểm tra nó.

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọcn digits is called an Armstrong number of order n [order is number of digits] if.

    abcd... = pow[a,n] + pow[b,n] + pow[c,n] + pow[d,n] + .... 

    Example:

    Input : 153
    Output : Yes
    153 is an Armstrong number.
    1*1*1 + 5*5*5 + 3*3*3 = 153
    
    Input : 120
    Output : No
    120 is not a Armstrong number.
    1*1*1 + 2*2*2 + 0*0*0 = 9
    
    Input : 1253
    Output : No
    1253 is not a Armstrong Number
    1*1*1*1 + 2*2*2*2 + 5*5*5*5 + 3*3*3*3 = 723
    
    Input : 1634
    Output : Yes
    1*1*1*1 + 6*6*6*6 + 3*3*3*3 + 4*4*4*4 = 1634

    Bàn luận

    Cho một số X, xác định xem số đã cho có phải là số Armstrong hay không. Một số nguyên dương của n chữ số được gọi là số lượng đơn đặt hàng n [thứ tự là số chữ số] nếu.

    Python

    def

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    0

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    1
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    2
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    3
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    6
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    7

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    8
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    9
    # Python program to check if the number is an Armstrong number or not
    
    # take input from the user
    num = int[input["Enter a number: "]]
    
    # initialize sum
    sum = 0
    
    # find the sum of the cube of each digit
    temp = num
    while temp > 0:
       digit = temp % 10
       sum += digit ** 3
       temp //= 10
    
    # display the result
    if num == sum:
       print[num,"is an Armstrong number"]
    else:
       print[num,"is not an Armstrong number"]
    
    0

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    1
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    2
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    3
    # Python program to check if the number is an Armstrong number or not
    
    # take input from the user
    num = int[input["Enter a number: "]]
    
    # initialize sum
    sum = 0
    
    # find the sum of the cube of each digit
    temp = num
    while temp > 0:
       digit = temp % 10
       sum += digit ** 3
       temp //= 10
    
    # display the result
    if num == sum:
       print[num,"is an Armstrong number"]
    else:
       print[num,"is not an Armstrong number"]
    
    4
    # Python program to check if the number is an Armstrong number or not
    
    # take input from the user
    num = int[input["Enter a number: "]]
    
    # initialize sum
    sum = 0
    
    # find the sum of the cube of each digit
    temp = num
    while temp > 0:
       digit = temp % 10
       sum += digit ** 3
       temp //= 10
    
    # display the result
    if num == sum:
       print[num,"is an Armstrong number"]
    else:
       print[num,"is not an Armstrong number"]
    
    5
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    6
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    7

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    8
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    9
    Enter a number: 663
    663 is not an Armstrong number
    
    2
    Enter a number: 663
    663 is not an Armstrong number
    
    3
    Enter a number: 663
    663 is not an Armstrong number
    
    3
    # Python program to check if the number is an Armstrong number or not
    
    # take input from the user
    num = int[input["Enter a number: "]]
    
    # initialize sum
    sum = 0
    
    # find the sum of the cube of each digit
    temp = num
    while temp > 0:
       digit = temp % 10
       sum += digit ** 3
       temp //= 10
    
    # display the result
    if num == sum:
       print[num,"is an Armstrong number"]
    else:
       print[num,"is not an Armstrong number"]
    
    5
    Enter a number: 663
    663 is not an Armstrong number
    
    6__

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    1
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    9
    Enter a number: 407
    407 is an Armstrong number
    
    5
    Enter a number: 663
    663 is not an Armstrong number
    
    7
    Enter a number: 663
    663 is not an Armstrong number
    
    2
    Enter a number: 663
    663 is not an Armstrong number
    
    3__

    def

    num = 1634
    
    # Changed num variable to string, 
    # and calculated the length [number of digits]
    order = len[str[num]]
    
    # initialize sum
    sum = 0
    
    # find the sum of the cube of each digit
    temp = num
    while temp > 0:
       digit = temp % 10
       sum += digit ** order
       temp //= 10
    
    # display the result
    if num == sum:
       print[num,"is an Armstrong number"]
    else:
       print[num,"is not an Armstrong number"]
    
    9

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    1
    abcd... = pow[a,n] + pow[b,n] + pow[c,n] + pow[d,n] + .... 
    1
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    6

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    1
    abcd... = pow[a,n] + pow[b,n] + pow[c,n] + pow[d,n] + .... 
    5
    abcd... = pow[a,n] + pow[b,n] + pow[c,n] + pow[d,n] + .... 
    6
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    6
    abcd... = pow[a,n] + pow[b,n] + pow[c,n] + pow[d,n] + .... 
    9

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    8
    abcd... = pow[a,n] + pow[b,n] + pow[c,n] + pow[d,n] + .... 
    1
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    abcd... = pow[a,n] + pow[b,n] + pow[c,n] + pow[d,n] + .... 
    1
    Input : 153
    Output : Yes
    153 is an Armstrong number.
    1*1*1 + 5*5*5 + 3*3*3 = 153
    
    Input : 120
    Output : No
    120 is not a Armstrong number.
    1*1*1 + 2*2*2 + 0*0*0 = 9
    
    Input : 1253
    Output : No
    1253 is not a Armstrong Number
    1*1*1*1 + 2*2*2*2 + 5*5*5*5 + 3*3*3*3 = 723
    
    Input : 1634
    Output : Yes
    1*1*1*1 + 6*6*6*6 + 3*3*3*3 + 4*4*4*4 = 1634
    4
    # Python program to check if the number is an Armstrong number or not
    
    # take input from the user
    num = int[input["Enter a number: "]]
    
    # initialize sum
    sum = 0
    
    # find the sum of the cube of each digit
    temp = num
    while temp > 0:
       digit = temp % 10
       sum += digit ** 3
       temp //= 10
    
    # display the result
    if num == sum:
       print[num,"is an Armstrong number"]
    else:
       print[num,"is not an Armstrong number"]
    
    0

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    8
    Enter a number: 407
    407 is an Armstrong number
    
    5
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    Enter a number: 407
    407 is an Armstrong number
    
    5
    Enter a number: 663
    663 is not an Armstrong number
    
    3
    Enter a number: 663
    663 is not an Armstrong number
    
    3
    The given number 153 is armstrong number
    2

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    1
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    9
    The given number 153 is armstrong number
    5

    def

    The given number 153 is armstrong number
    7

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    1
    abcd... = pow[a,n] + pow[b,n] + pow[c,n] + pow[d,n] + .... 
    1
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4 def1

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    1def3
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4 def5

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    1def7
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    6

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    1
    abcd... = pow[a,n] + pow[b,n] + pow[c,n] + pow[d,n] + .... 
    5
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    02
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    6
    abcd... = pow[a,n] + pow[b,n] + pow[c,n] + pow[d,n] + .... 
    9

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    8
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    07
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4 def3
    # Python program to check if the number is an Armstrong number or not
    
    # take input from the user
    num = int[input["Enter a number: "]]
    
    # initialize sum
    sum = 0
    
    # find the sum of the cube of each digit
    temp = num
    while temp > 0:
       digit = temp % 10
       sum += digit ** 3
       temp //= 10
    
    # display the result
    if num == sum:
       print[num,"is an Armstrong number"]
    else:
       print[num,"is not an Armstrong number"]
    
    4
    The given number 153 is armstrong number
    2

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    8def7
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4 def7
    Input : 153
    Output : Yes
    153 is an Armstrong number.
    1*1*1 + 5*5*5 + 3*3*3 = 153
    
    Input : 120
    Output : No
    120 is not a Armstrong number.
    1*1*1 + 2*2*2 + 0*0*0 = 9
    
    Input : 1253
    Output : No
    1253 is not a Armstrong Number
    1*1*1*1 + 2*2*2*2 + 5*5*5*5 + 3*3*3*3 = 723
    
    Input : 1634
    Output : Yes
    1*1*1*1 + 6*6*6*6 + 3*3*3*3 + 4*4*4*4 = 1634
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    17

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    8def3
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4 def3
    Enter a number: 663
    663 is not an Armstrong number
    
    3
    Enter a number: 663
    663 is not an Armstrong number
    
    3
    The given number 153 is armstrong number
    2

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    34
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    35

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    1
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    9
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    27
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    30

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    34
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    35

    Enter a number: 407
    407 is an Armstrong number
    
    5
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    33
    O[[logn]2]

    Enter a number: 407
    407 is an Armstrong number
    
    5
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    38
    O[1]

    Độ phức tạp về thời gian: O [[logn] 2]A positive integer is called an Armstrong number if an Armstrong number of 3 digits, the sum of cubes of each digit is equal to the number itself. For example, 153 is an Armstrong number because
       153 = 1*1*1 + 5*5*5 + 3*3*3
        The while loop iterates like first, it checks if the number is not equal to zero or not. if it is not equal to zero then enter into the loop and find the reminder of number ex: 153%10 gives reminder 3. In the next step add the cube of a number to the sum1[3*3*3]. Then the step gives the quotient of the number [153//10=15]. this loop will continue till the given number is equal to zero.
     

    Python3

    Không gian phụ trợ: O [1]

    Phương pháp: Một số nguyên dương được gọi là số Armstrong nếu số lượng 3 chữ số của Armstrong, tổng số khối của mỗi chữ số bằng chính số. Ví dụ, 153 là một số Armstrong vì & nbsp; & nbsp; 153 = 1*1*1 + 5*5*5 + 3*3*3 & nbsp; & nbsp; Vòng lặp trong khi lặp lại như đầu tiên, nó kiểm tra xem số không bằng 0 hay không. Nếu nó không bằng 0 thì hãy nhập vào vòng lặp và tìm lời nhắc của số EX: 153%10 đưa ra lời nhắc 3. Trong bước tiếp theo, hãy thêm khối của một số vào SUM1 [3*3*3]. Sau đó, bước đưa ra thương số của số [153 // 10 = 15]. Vòng lặp này sẽ tiếp tục cho đến khi số đã cho bằng 0. & NBSP;

    abcd... = pow[a,n] + pow[b,n] + pow[c,n] + pow[d,n] + .... 
    1
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4 ________ 133 & nbsp;

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    44
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    46

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    47
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    49
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    50
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    51
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    52

    def7

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    6

    abcd... = pow[a,n] + pow[b,n] + pow[c,n] + pow[d,n] + .... 
    5
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    57
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    6
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    7

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    1
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    07
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    abcd... = pow[a,n] + pow[b,n] + pow[c,n] + pow[d,n] + .... 
    1
    # Python program to check if the number is an Armstrong number or not
    
    # take input from the user
    num = int[input["Enter a number: "]]
    
    # initialize sum
    sum = 0
    
    # find the sum of the cube of each digit
    temp = num
    while temp > 0:
       digit = temp % 10
       sum += digit ** 3
       temp //= 10
    
    # display the result
    if num == sum:
       print[num,"is an Armstrong number"]
    else:
       print[num,"is not an Armstrong number"]
    
    4
    The given number 153 is armstrong number
    2

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    1def7
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    70
    Input : 153
    Output : Yes
    153 is an Armstrong number.
    1*1*1 + 5*5*5 + 3*3*3 = 153
    
    Input : 120
    Output : No
    120 is not a Armstrong number.
    1*1*1 + 2*2*2 + 0*0*0 = 9
    
    Input : 1253
    Output : No
    1253 is not a Armstrong Number
    1*1*1*1 + 2*2*2*2 + 5*5*5*5 + 3*3*3*3 = 723
    
    Input : 1634
    Output : Yes
    1*1*1*1 + 6*6*6*6 + 3*3*3*3 + 4*4*4*4 = 1634
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    72
    Enter a number: 663
    663 is not an Armstrong number
    
    7
    Enter a number: 663
    663 is not an Armstrong number
    
    7
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    75

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    1
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    34
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    50
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    91
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    92
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    93
    Enter a number: 407
    407 is an Armstrong number
    
    2

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    95
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    7

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    1
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    34
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    50
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    91
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    92
    # Python program to check if the number is an Armstrong number or not
    
    # take input from the user
    num = int[input["Enter a number: "]]
    
    # initialize sum
    sum = 0
    
    # find the sum of the cube of each digit
    temp = num
    while temp > 0:
       digit = temp % 10
       sum += digit ** 3
       temp //= 10
    
    # display the result
    if num == sum:
       print[num,"is an Armstrong number"]
    else:
       print[num,"is not an Armstrong number"]
    
    02
    Enter a number: 407
    407 is an Armstrong number
    
    2

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    1
    abcd... = pow[a,n] + pow[b,n] + pow[c,n] + pow[d,n] + .... 
    1
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    The given number 153 is armstrong number
    5
    Enter a number: 663
    663 is not an Armstrong number
    
    3
    Enter a number: 663
    663 is not an Armstrong number
    
    3
    The given number 153 is armstrong number
    2

    The given number 153 is armstrong number

    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    2
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    44
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    87

    Đầu raO[logn]

    Enter a number: 407
    407 is an Armstrong number
    
    5
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    4
    153 = 1*1*1 + 5*5*5 + 3*3*3  // 153 is an Armstrong number.
    
    38
    O[1]


    Làm thế nào để bạn làm số Armstrong trong Python?

    Mã nguồn để kiểm tra số lượng n chữ số n của n 0; orinum /= 10] {phần còn lại = orinum % 10; // lưu trữ tổng sức mạnh của các chữ số riêng lẻ trong kết quả kết quả += pow [phần còn lại, n]; } if [[int] result == numb] printf ["%d là số armstrong.

    Số Armstrong trong Python sử dụng cho Loop là gì?

    Trong trường hợp số lượng 3 chữ số của Armstrong, tổng khối của mỗi chữ số bằng chính với số lượng.Ví dụ: 153 = 1*1*1 + 5*5*5 + 3*3*3 // 153 là số Armstrong.the sum of cubes of each digit is equal to the number itself. For example: 153 = 1*1*1 + 5*5*5 + 3*3*3 // 153 is an Armstrong number.

    Làm thế nào để bạn tìm thấy số Armstrong trong một hàm?

    C chương trình để kiểm tra số Armstrong bằng chức năng..
    int Check_armstrong [L];L Power [int, int] ;.
    int main [] {l n ;.
    printf ["nhập một số \ n"];Scanf ["%lld", & n] ;.
    if [Check_armstrong [n] == 1] printf ["%lld là số armstrong. \ ....
    trả lại 0;}.
    int Check_armstrong [l n] {l sum = 0, t;....
    while [t! = 0] {....
    while [t! = 0] {.

    Làm cách nào để in 5 số Armstrong đầu tiên trong Python?

    In các số Armstrong "N" đầu tiên bằng cách sử dụng Python, chúng ta có thể làm điều này chỉ bằng cách sử dụng một vòng chạy từ 1 đến số Armstrong thứ n.Chúng ta có thể sử dụng biến "đếm" và khởi tạo nó thành 0 để theo dõi số lượng số Armstrong đã được tìm thấy.using a loop that runs from 1 to the Nth Armstrong number. We can use a "count" variable and initialize it to zero to keep track of how many Armstrong numbers have been found.

    Bài Viết Liên Quan

    Chủ Đề