Thursday, 26 January 2012

Write a C program to check whether the given integer is Magic number or not.

Magic number:- A number which is divisible by 9 and also after reverse if it is divisible by 9, then it is said to Magic number.

Example:- Suppose take 18
We know '18' is divisible by 9 (ie., 9 * 2 = 18)
Now After reverse '18' becomes 81.
Here '81' is also is divisible by 9 (ie., 9 * 9 =81 )
So we say '18' is a Magic number.


#include<stdio.h>
#include<conio.h>
void main( )
{
    int rem, rev=0, n;
    clrscr( );
    printf("Enter the required number:");
    scanf("%d",&n);
    while(n>0)
    {
        rem=n%10;
        rev=(10*rev)+ rem;
        n=n/10;
    }
    if(rev%9== 0)
    printf("\nMagic Number.");
    else
    printf("\nNot a Magic number.");
    getch( );
}

Output:-
Enter the required number: 27
Magic Number.

No comments:

Post a Comment