Computer Science, asked by SƬᏗᏒᏇᏗƦƦᎥᎧƦ, 4 days ago

Question in attachment.
Don't SpaM​

Attachments:

Answers

Answered by anindyaadhikari13
11

\textsf{\large{\underline{Solution}:}}

The given co‎de 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}:}}

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}:}}

> a = 1

> b = 100

Magic Number in the given range are: 1 10 19 28 37 46 55 64 73 82 91 100

Attachments:

anindyaadhikari13: Thanks for the brainliest :)
Answered by GlossBabe
2

{\huge{\pink{↬}}} \:  \: {\huge{\underline{\boxed{\bf{\pink{Answer}}}}}}

The given co‎de 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

Similar questions