Knowee
Questions
Features
Study Tools

Write a python program to check the given number is Armstrong or not usingwhile loop.

Question

Write a python program to check the given number is Armstrong or not usingwhile loop.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a Python program that checks if a given number is an Armstrong number or not using a while loop:

# Function to check if a number is Armstrong
def is_armstrong(num):
    # Initialize sum
    sum = 0
    # Find the number of digits
    temp = num
    while temp > 0:
        digit = temp % 10
        sum += digit ** 3
        temp //= 10

    # If the sum is equal to the original number, it is an Armstrong number
    if num == sum:
        return True
    return False

# Test the function
num = int(input("Enter a number: "))
if is_armstrong(num):
    print(num,"is an Armstrong number")
else:
    print(num,"is not an Armstrong number")

This program works by taking a number as input and checking if it is an Armstrong number. An Armstrong number is a number that is equal to the sum of cubes of its digits. For example, 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153. The program uses a while loop to calculate the sum of cubes of the digits of the number. If the sum is equal to the original number, the number is an Armstrong number.

This problem has been solved

Similar Questions

Write a C program to check whether a number is Armstrong number or not.

Write a C program to determine if a given integer is an Armstrong number or not. An Armstrong number (also known as a narcissistic number or pluperfect digital invariant) is a number that is equal to the sum of its own digits raised to the power of the number of digits. For example, 153 is an Armstrong number because 13+53+33=15313+53+33=153.Design a function called isArmstrong that takes an integer num as input and returns 1 if num is an Armstrong number, and 0 otherwise. Your program should prompt the user to enter an integer, call the isArmstrong function to check if it is an Armstrong number, and display an appropriate message indicating whether the entered number is an Armstrong number or not.inputEnter a number: 153output153 is an Armstrong number.

Complete the code segment to check whether the number is an Armstrong number or not.Armstrong Number:

int originalNumber, remainder, result = 0, count = 0; originalNumber = n; // To get the number of digits while (originalNumber != 0) { originalNumber /= 10; ++count; } originalNumber = n; // Check if the number is an Armstrong number while (originalNumber != 0) { remainder = originalNumber % 10; result += pow(remainder, count); originalNumber /= 10; } if (result == n) return 1; else return result; } :36:1: error: expected identifier or ( before } token 44 | } showing this error

You are given an integer 'n'. Return 'true' if 'n' is an Armstrong number, and 'false' otherwise.An Armstrong number is a number (with 'k' digits) such that the sum of its digits raised to 'kth' power is equal to the number itself. For example, 371 is an Armstrong number because 3^3 + 7^3 + 1^3 = 371.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.