Computer Science, asked by nagsushma13, 17 days ago

wap to enter a number and check whether its magic number or not.
A number us said to be a magic number if the eventual sum of digits of the number is one .
For eg:-
Input : 55
5 + 5 = 10
Output : It's not a magic no.
Input : 10
1 + 0 = 1
Output : it's a magic no.​

Answers

Answered by priyanka4212
2

Answer:

Computer Applications

Write a program to input a number and check whether it is 'Magic Number' or not. Display the message accordingly.

A number is said to be a magic number if the eventual sum of digits of the number is one.

Sample Input : 55

Then, 5 + 5 = 10, 1 + 0 = 1

Sample Output: Hence, 55 is a Magic Number.

Similarly, 289 is a Magic Number.

Java

Java Nested for Loops

ICSE

21 Likes

ANSWER

import java.util.Scanner;

public class KboatMagicNum

{

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

System.out.print("Enter number to check: ");

int num = in.nextInt();

int n = num;

while (n > 9) {

int sum = 0;

while (n != 0) {

int d = n % 10;

n /= 10;

sum += d;

}

n = sum;

}

if (n == 1)

System.out.println(num + " is Magic Number");

else

System.out.println(num + " is not Magic Number");

}

}

OUTPUT

Similar questions