Write a program to check given number is armstrong or not.
SOLUTION:
/* * Program for checking Armstrong number * Written by Shaeed Khan. * Date: 04 Aug 2014 * Version- 1.0 * Language: C */ #include < stdio.h > #include < stdlib.h > void main() { int n,x; printf("Enter a number:"); scanf("%d",&n); x=armstrong(n); if(x==n) printf("Arm strong"); else printf("Not arm strong"); } int armstrong(int num) { int sum=0,r; while(num!=0) { r=num%10; num=num/10; sum=sum+(r*r*r); } return sum; }
No comments:
Post a Comment