C Program to display whether given number is Magic or not
#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;
}
Output:-
Enter number to find out magic number or not
1729
1729 is a Magic Number
Post a Comment
If you have any doubts, Please let me know
Thanks!