How to check if a number is Magic Number using C programming Language!
#include <stdio.h>
#include <math.h>
void main(){
int m,n,o,i,j,sum = 0,total = 0;
scanf("%d",&o);
for(i = o;i>0;i/=10){
m = i % 10;
sum = sum + m;
}
for(j = sum ;j>0;j/=10){
n = j % 10;
total = total + n;
}
if(total == 1){
printf("%d is a Magic Number",o);
}
}
Comments
Post a Comment