Write a program to input a no. and print if it's Armstrong or not. tell only the answer which is correct .
Answers
Answer:
Let's see the c program to check Armstrong Number in C.
#include<stdio.h>
int main()
{
int n,r,sum=0,temp;
printf("enter the number=");
scanf("%d",&n);
temp=n;
Answer:
Answer:
Write a program to input a no. and print if it's Armstrong or not.
import java.util.Scanner ;
public class Armstrong
{
public static void main (String args[ ] )
{
Scanner sc = new Scanner(System.in) ;
System.out.print("Enter a 3digit number to be checked:") ;
int num= sc.nextInt( ) ;
int check = 0, remainder;
do {
remainder = n % 10 ;
check = check + (int)Math.pow(remainder,3) ;
n = n / 10 ;
} while (n != 0) ;
if (check = = num )
System.out.println(num + "is an Armstrong Number") ;
else
System.out.println(num + "is not a Armstrong Number") ;
}
}
Example output:
Enter a 3 digit number to be checked : 345
345 is not a Armstrong number