C Program to Check Whether Number is Magic or Not on Command Line

Hello Geeks! If you are interested to learn about “C Program to Check Whether Number is Magic or Not on Command Line” then read this article to learn about it. Let’s go for an article directly.

C Program to Check Whether Number is Magic or Not on Command Line

C Program to Check Whether Number is Magic or Not on Command Line

Program Code

#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int num, temp, rev=0, digit, sumOfDigits=0;
 
    printf("Enter a Number n");
    scanf("%d",&num);
    
    
    temp = num;
 
    //Calculating Sum of digits
    while(temp > 0){
        //Extract digit and add them
        sumOfDigits += temp % 10;  
        temp = temp / 10;      
    }

 
   temp = sumOfDigits;

    //Compute reverse of Sum of Digits
    while( temp > 0){
        rev = rev*10 + temp % 10; 
        temp = temp / 10;
    }
 
    if(rev*sumOfDigits == num)
        printf("Magic Number n");
    else
        printf("Not a Magic Number n");
 
    return 0;
}

Final Thoughts

I hope this article helps you to know the concept “C Program to Check Whether Number is Magic or Not on Command Line” clearly. If you face any issues please let me know via the comment section. Share this article with other C/C++ developers via social networks. 

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment