Question in attachment.
Don't SpaM
Answers
The given code is written using language - Java.
public class Java{
public static void main(int a,int b){
System.out.print("Magic Number in the given range are: ");
for(int i=a;i<=b;i++){
if(isMagic(i))
System.out.print(i+" ");
}
}
static boolean isMagic(int a){
return a%9==1;
}
}
A number is said to be a magic number if the recursive sum of its digit is 1.
Example: 82
> 8 + 2 = 10
> 1 + 0 = 1
Hence, it is a magic number. A magic number always leaves 1 as remainder when divided by 9. Using this logic, problem is solved.
> a = 1
> b = 100
Magic Number in the given range are: 1 10 19 28 37 46 55 64 73 82 91 100
The given code is written using language - Java.
public class Java{
public static void main(int a,int b){
System.out.print("Magic Number in the given range are: ");
for(int i=a;i<=b;i++){
if(isMagic(i))
System.out.print(i+" ");
}
}
static boolean isMagic(int a){
return a%9==1;
}
}
\textsf{\large{\underline{Explanation}:}}
Explanation
:
A number is said to be a magic number if the recursive sum of its digit is 1.
Example: 82
> 8 + 2 = 10
> 1 + 0 = 1
Hence, it is a magic number. A magic number always leaves 1 as remainder when divided by 9. Using this logic, problem is solved.
\textsf{\large{\underline{Sample I/O}:}}
Sample I/O
:
> a = 1
> b = 100
Magic Number in the given range are: 1 10 19 28 37 46 55 64 73 82 91 100