Examples of C part 31 check numbers is magic or not
Program:
Output:
Enter number to find out magic number or not
1729
1729 is a Magic NumberExplanation:
#include<stdio.h> int GetSumOfDigits(int num); int GetReverseOfNumber(int sumOfDigits); main() { int num,sumOfDigits,reverseOfNumber; printf("Enter number to find out magic number or not\n"); scanf("%d",&num); sumOfDigits=GetSumOfDigits(num); reverseOfNumber=GetReverseOfNumber(sumOfDigits); if(sumOfDigits*reverseOfNumber==num) { printf("%d is a Magic Number\n",num); } else { printf("%d is not a Magic Number\n",num); } } int GetSumOfDigits(int n) { int sum=0,x; while(n>0) { x=n%10; sum=sum+x; n=n/10; } return sum; } int GetReverseOfNumber(int n) { int rev=0,x; while(n>0) { x=n%10; rev=rev*10+x; n=n/10; } return rev; }
Enter number to find out magic number or not
1729
1729 is a Magic NumberExplanation:
1729---->1+7+2+9= 19//Sum of all digits from given number Reverse of Sum of digits=91 19*91=1729 so it is magic number