23.12.19

Armstrong number program in c

Armstrong Number(Or Narcissistic Number):
An Armstrong number is a number such that the sum of its digits raised to the no.of digits power is equal to the number itself.
Explnation:To declare a number is an Armstrong number, first determine how many digits are in the number. Call that n. Then take every digit in the number and raise it to the n power. Add all those together, and if your answer is the original number then it is an "Armstrong Number"



#include<stdio.h>

void main()
{

int number,orignum,rem,result=0;

printf("enter a three digit number to check whether it is armstrong or not");

scanf("%d",&number);

orignum=number;

while(orignum!=0)
{
rem=orignum%10;
result+rem*rem*rem;
orignum=orignum/10;
}

if(result==number)

printf("%d is armstrong number ",number);

else

printf("%d is not armstrong number",number);

}


OUTPUT:
1:  enter a three digit number to check whether it is armstrong or not   371
     
     371 is armstrong number

2:  enter a three digit number to check whether it is armstrong or not   456     
     456 is not  armstrong number

No comments:

Post a Comment

JAVA program pattern 2

import java.util.Scanner; public class pattern3 { public static void main(String args[]) { int i,j; Scanner sc=new Scanner(System.in); Syste...