Prerequisite:
Armstrong number: A three digit number is an Armstrong number if the sum of cube of each digit equals to the number itself. e.g
153= 1^3 +5^3 +3^3 (cube because total digit in number 3)
1634= 1^4 +6^4 +3^4 +4^4 (power 4 because total digit in number 4)
Program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
#include<stdio.h> int main() { unsigned long int numb,numb_temp,sum=0; unsigned long int r; printf("\n Program to find factorial of any number"); printf("\nPlease enter any Number: "); scanf("%ld",&numb); numb_temp=numb; while(numb_temp>0) { r=numb_temp%10; sum=sum+(r*r*r); numb_temp=numb_temp/10; } printf("\nsum of cubes of digits of %ld is= %ld",numb,sum); if(numb==sum) { printf("\nSo %ld is armstrong",numb); } else { printf("\nSo %ld is Not armstrong",numb); } return 0; } |
1 2 3 4 5 6 |
Output: Program to find factorial of any number Please enter any Number: 153 sum of cubes of digits of 153 is= 153 So 153 is armstrong |