Find armstrong number #include < stdio.h > int main() { int number, sum = 0, temp, remainder; printf("Enter an integer\n"); scanf("%d",&number); temp = number; /*if sum of cubes of each digit in a number is same as the number then it is called as armstrong no.*/ while( temp != 0 ) { remainder = temp%10; sum = sum + remainder*remainder*remainder; temp = temp/10; /*taking unit place digits cube and adding into sum*/ } if ( number == sum ) printf("Entered number is an armstrong number.\n"); else printf("Entered number is not an armstrong number.\n"); return 0; }
Comments
Post a Comment