Showing posts with label to check whether a number is armstrong number or not. Show all posts
Showing posts with label to check whether a number is armstrong number or not. Show all posts

Thursday, 14 May 2015

Python Program to check a number is Armstrong number or not


This a Python program to check whether a given number is armstrong or not .
Generally a number is said to be an armstrong number if the cubes of the digits is equal to its original number .





PROGRAM  :
num = int(input('Enter any number : '))
sum = 0
copy = num
while copy > 0:
    remainder=copy%10
    sum += remainder ** 3
    copy //= 10
if num == sum:
    print(num,"is an Armstrong number")
else:
    print(num,"is an not Armstrong number")


OUTPUT : 
Python - Armstrong or not

Python - Armstrong or not




Similar Programs :  
C Program to check a number is Armstrong number or not
Cpp Program to check a number is Armstrong number or not
Java Program to check a number is Armstrong number or not

Monday, 5 January 2015

Java Program to check whether a number is an Armstrong number or not


This a Java program to check whether a given number is armstrong or not .
Generally a number is said to be an armstrong number if the cubes of the digits is equal to its original number .

For Example : 153 is an armstrong number as 1³ + 5³ + 3³ = 153  whereas 234 is not an armstrong number as 2³+ 3³+ 4³ is not equal to 234.


PROGRAM :
package codingcorner.in;

import java.util.Scanner;

public class Armstrong {
 public static void main(String[] args) {
  int number, num, sum = 0, remainder;
  Scanner scan = new Scanner(System.in);
  System.out.println("Enter any number :\t");
  number = scan.nextInt();
  scan.close();
  num = number;
  while (num != 0) {
   remainder = num % 10;
   sum = sum + remainder * remainder * remainder;
   num = num / 10;
  }
  if (number == sum)
   System.out.println(number + "  is an Armstrong number");
  else
   System.out.println(number + "  is an not an Armstrong number");
 }
}

OUTPUT :






Related Programs :
Palindrome number in C      
Palindrome number in Cpp
Reverse of a number in Java      
Palindrome number in Java
Reverse of a number in C       
Reverse Of a number in Cpp
Armstrong number in C 
Armstrong number in Cpp

Saturday, 3 January 2015

Cpp Program to check whether a number is Armstrong number or not



This a Cpp program to check whether a given number is armstrong or not .
Generally a number is said to be an armstrong number if the cubes of the digits is equal to its original number .

For Example : 153 is an armstrong number as 1³ + 5³ + 3³ = 153 whereas 234 is not an armstrong number as 2³+ 3³+ 4³ is not equal to 234.


PROGRAM :
#include <iostream>

using namespace std;

int main()
{
    int n,copy_num,remainder,sum = 0;
    cout << "Enter a number : \t" ;
    cin >> n;
    copy_num = n;
    
    while(n)
    {
        remainder = n%10;
        sum=sum+remainder*remainder*remainder;
        n=n/10;
    }
    if(copy_num == sum)
    cout << copy_num << " is an ARMSTRONG number" << endl;
    else
        cout << copy_num << " is an  not an armstrong number" << endl;
    return 0;
}
OUTPUT :









Related Programs : 
Armstrong numberin C

Palindrome number in Cpp
Palindrome number in C
Reverse of a number in C
Average of N numbers in Cpp
Average of N numbers in C