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) // place this '<' & '>' instead of '(' & ')' before 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.
Note:- If u have any doubt regarding this program or logic, please feel free to contact me.
Monday, February 16, 2009
Subscribe to:
Post Comments (Atom)
i want to know about the whole meaning of the program cause I've tried this but its not working
ReplyDeletewhat is mean by magic no.
ReplyDeletei want to print all the numbers which are magic numbers how can i write it
ReplyDeleteno..its wrong logic
ReplyDeletethe actual logic is ...
suppse we have no. 9
its square 81...divide this no in two parts so....8 and 1
and then addition between them ...you get 9 again...is called magic no.
ex. no. 99 also magic no.
so 99*99=9801...dividing the no in two part ...
so 98 and 01....now addition between then...98+01 you get 99 again
this is the logic of automorphic number
DeleteHey i wanna have acomplete program...
DeleteHey i wanna have acomplete program...
Deletethat's wrong...
ReplyDeletemagic numbers like 153,
ReplyDelete1^3 + 5^3 + 3^3=153 =>1+125+27=153
the cube of all digits is = the same digit.
the code is below
public void magic()
{
int a = 53, b,rev=0,s=0;
int m=a, j=0;
while (a > 0)
{
b = a % 10;
rev = (b * b* b);
j = j + rev;
a = a / 10;
}
if (j == m)
Console.WriteLine("the no is a magic no");
else
Console.WriteLine("not magic no");
Jagdish thats Amstrong number
Deletethis is not magic number dude, it is called armstrong no...
DeleteJagadish Sati : Actually this is the logic for armstrong number.
ReplyDeleteI want to know...that how to initialize the counter in for loop..mainy iI have problem that sometimes we start it from number entered from user and often from 1 .....why..?
ReplyDeleteI learn totally different about magic number...
ReplyDeletei cant understand
ReplyDeleteA number is magical if repeated adding of its digit gives 1. example 19 is magical
ReplyDeleteas 1 + 9 = 10, 1 + 0
= 1 hence magical. So is 991 as 9 + 9 + 1 = 19, 1 + 9 = 10, 1 + 0 = 1. However 224
is not.
Input a range from user and print all the magic numbers in that range.
Delete#include
int main()
{
int low=0,high=0;
printf("Enter the range: low,high");
scanf("%d,%d",&low,&high);
int i=0;
for(i = low; i<= high ;i++)
{
int n = i,sum = n;
while(sum > 9)
{
n = sum;
sum = 0;
while(n > 0)
{
int digit = n%10;
n = n/10;
sum = sum + digit;
}
}
if(sum == 1)
{
printf(" %d is a magic number \n",i);
}
}
return 0;
}
You are the correct man
DeleteI am agree with Pawan Pandey about Magic number that sum must be 1 at the end.
ReplyDeleteits wrong....!!
ReplyDeleteInstead of trying to put me down to feel Good about yourself why don’t you try to make some achievements yourself to feel better?"
ReplyDeleteMight be helpfull to sombody in need: if anybody want to install mac os x directly in non apple laptop without using vmware/virtualbox
ReplyDeletepawanpandeya07.blogspot.in
Its A wrong concept
ReplyDeleteIts A wrong concept
ReplyDeleteThis is the correct program
ReplyDelete#include
/* sum of digits of a number */
int sumOfDigits(int num) {
int sum = 0;
while (num > 0) {
sum = sum + (num % 10);
num = num / 10;
}
return sum;
}
/* returns reverse of a given number */
int reverse(int num) {
int rev = 0;
while (num > 0) {
rev = (rev * 10) + (num % 10);
num = num / 10;
}
return rev;
}
int main () {
int num, sum, rev;
/* get the input value from the user */
printf("Enter the value for num:");
scanf("%d", &num);
/* find sum of digits */
sum = sumOfDigits(num);
/*
* if the value is single digit, then
* the value and its reverse are same
*/
if (sum < 10) {
if ((sum * sum) == num) {
printf("%d is a magic number\n", num);
} else {
printf("%d is not a magic number\n", num);
}
return 0;
}
/* reverse of the given number */
rev = reverse(sum);
/* print the outputs */
if ((sum * rev) == num) {
printf("%d is a magic number\n", num);
} else {
printf("%d is not a magic number\n", num);
}
return 0;
}
Example: 1729
ReplyDeleteFind the sum of digits of the given number.(1 + 7 + 2 + 9 => 19)
Reverse of digit sum output. Reverse of 19 is 91
Find the product of digit sum and the reverse of digit sum.(19 X 91 = 1729)
If the product value and the given input are same, then the given number is a magic number.(19 X 91 <=> 1729)
So, 1729 is a magic number.
The logics are wrong
ReplyDeleteeg-73
7+3=10
1+0=1
the final result should be one digit number
and should be 1
Plz be clear it is awrong one
ReplyDeletePlz be clear it is awrong one
ReplyDelete