Skip to main content
New Participant
May 26, 2023
Question

check Armstrong

  • May 26, 2023
  • 6 replies
  • 8 views

write a program to check whether it is a Armstrong or not ?

Input : 153
Output : Yes


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

    6 replies

    Participating Frequently
    May 26, 2023

    a!localVariables(
      local!n:tostring(ri!num),
      if(sum( power(a!forEach(
        items: enumerate(len(local!n))+1,
        expression: charat(ri!num,fv!item) ),3)) ==ri!num,"yes it is Armstrong number", "no it is not a Armstrong number"))

    harshitb6843
    Brainy
    May 26, 2023

    Did you try anything yourself? Where did you reach? 
    And why don't you use the internet to get answers to such basic problems from sites like stackoverflow or geeksforgeeks?

    anmolv0003
    Participating Frequently
    May 26, 2023

    a!localVariables(
    local!a: sum(
    power(
    tointeger(char(code(ri!num))),
    len(ri!num)
    )
    ),
    if(
    local!a = ri!num,
    ri!num & " is an Armstrong Number",
    ri!num & " is not an Armstrong Number"
    ),
    
    )

    Anmol
    harshitb6843
    Brainy
    May 26, 2023

    anmolv0003
    Participating Frequently
    May 26, 2023

    Thank you Sir. Will take care of this from the next time.

    Anmol