Home Programs Write a Program to print Armstrong number – Technic Dude

Write a Program to print Armstrong number – Technic Dude

0
10

Write a Program to find Armstrong number in c language , java language and python language by technic dude

<img width=
<img loading=

Write a program of Armstrong Number in C

#include<stdio.h>  
 int main()    
{    
int n,r,sum=0,temp;    
printf("enter the number=");    
scanf("%d",&n);    
temp=n;    
while(n>0)    
{    
r=n%10;    
sum=sum+(r*r*r);    
n=n/10;    
}    
if(temp==sum)    
printf("this is armstrong  number ");    
else    
printf("this is not armstrong number");    
return 0;  
}   

OUTPUT

enter the number=153
this is armstrong number

enter the number=5
this is not armstrong number

Write a program of Armstrong Number in JAVA

Here is question that Check Armstrong Number for 3 digit number

public class Armstrong {

    public static void main(String[] args) {

        int number = 153, originalNumber, remainder, result = 0;

        originalNumber = number;

        while (originalNumber != 0)
        {
            remainder = originalNumber % 10;
            result += Math.pow(remainder, 3);
            originalNumber /= 10;
        }

        if(result == number)
            System.out.println(number + " is Armstrong number.");
        else
            System.out.println(number + " is not Armstrong number.");
    }
}


OUTPUT

153 is Armstrong number.

Write a program of Armstrong Number in PYTHON

Here is question that Check Armstrong Number for 3 digit number in python

# 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 Armstrong number")
else:
   print(num,"is not Armstrong number")


OUTPUT

Enter a number: 153
153 is Armstrong number

READ MORE

NO COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here