Computer Science, asked by maths5813, 1 year ago

Write a program to check whether a number input by the user is Armstrong number or not.

Answers

Answered by RoyalBoy007
5

in c, c++

#include <stdio.h>

int main()

{

   int number, originalNumber, remainder, result = 0;

   printf("Enter a three digit integer: ");

   scanf("%d", &number);

   originalNumber = number;

   while (originalNumber != 0)

   {

       remainder = originalNumber%10;

       result += remainder*remainder*remainder;

       originalNumber /= 10;

   }

   if(result == number)

       printf("%d is an Armstrong number.",number);

   else

       printf("%d is not an Armstrong number.",number);

   return 0;

}

Answered by Brenquoler
0

An Armstrong number is a number whose sum of cubes of digits is equal to the number itself.

For example:

153 = 1³+5³+3³

1+125+27

=153

Program:

import java. util.*;

class Armstrong

{

public static void main (string args [])

{

Scanner sc = new Scanner

int n, r, p, s=0, m;

System.out.println ("Enter a number");

n=sc.nextInt();

while

{

r=n%10

p=r*r*r;

s=s+p;

n=n/10;

}

if (m==s)

System.out.println (m+"is Armstrong");

else

System.out.println (m+"is not Armstrong");

}

}

Similar questions