Adam Number In C Program

Example


where "^" represents the exponentiation operator and "reverse(n)" represents the number obtained by reversing the digits of "n". For example, 12 is an Adam number because:

12^2 = 144

reverse(12) = 21

reverse(144) = 441

(21)^2 = 441

Example


Therefore, 12 is an Adam number. To check if a given number is an Adam number, we need to perform the following steps:

- Compute the square of the number n.

- Reverse the digits of n and compute its square.

- Reverse the digits of the square obtained in step 2.

- Compare the result obtained in step 1 with the result obtained in step 3. If they are equal, then n is an Adam number; otherwise, it is not.

In C programming, we can implement this algorithm using basic arithmetic operations and a loop to reverse the digits of the number. Here is an example code:

C Code

include <stdio.h>

int reverse(int n) {

int rev = 0;

while (n > 0) {

rev = rev * 10 + n % 10;

n /= 10;

}

return rev;

}

int isAdam(int n) {

int n2 = n * n;

int revn = reverse(n);

int revn2 = reverse(n2);

int revn2sqr = revn2 * revn2;

return (n2 == revn2sqr);

}

int main {

int n;

printf("Enter a number: ");

scanf("%d", &n);

if (isAdam(n)) {

printf("%d is an Adam number.\n", n);

} else {

printf("%d is not an Adam number.\n", n);

}

return 0;

}

Example


Output

This code prompts the user to input an integer number and then checks whether it is an Adam number using the "isAdam" function defined in the code.

If the entered number is an Adam number, the program will output:

Enter a number: [number entered by user]

[number entered by user] is an Adam number.

Example


If the entered number is not an Adam number, the program will output:

Enter a number: [number entered by user]

[number entered by user] is not an Adam number.

Example


For example, if the user enters 12, which is an Adam number, the program will output:

Enter a number: [number entered by user]

[number entered by user] is not an Adam number.

Example


If the user enters 5, which is not an Adam number, the program will output:

Enter a number: 12

12 is an Adam number.

Example


Explanation:

In the initial scenario, when the input is 12, the software validates if 12 qualifies as an Adam number by invoking the "isAdam" subroutine. Initially, the subroutine computes the square of 12, resulting in 144. Subsequently, it determines the reverse of 12 as 21 and the reverse of 144 as 441. The next step involves calculating the square of 441, which equals 194481. Upon comparison of 144 and 194481, the subroutine confirms their equality, leading to a true outcome denoting that 12 indeed qualifies as an Adam number. Consequently, the software displays the notification "12 is an Adam number."

In the subsequent scenario, the user inputs the integer 5. The software validates if 5 qualifies as an Adam number by invoking the "isAdam" subroutine. Initially, the subroutine computes the square of 5, resulting in 25. Subsequently, it determines the reverse of 5, which is also 5, and the reverse of 25, which equals 52. Continuing, the subroutine calculates the square of 52, yielding 2704. Ultimately, a comparison is made between 25 and 2704. Given that they do not match, the subroutine concludes by returning false, signifying that 5 does not meet the criteria of an Adam number. Consequently, the software proceeds to display the notification "5 is not an Adam number."

In each scenario, the software employs a consistent method to ascertain whether the provided number qualifies as an Adam number. It involves computing the square of the number, reversing the number, reversing the square of the number, and squaring the reverse of the square of the number. Subsequently, it compares the square of the number with the square of the reverse of the square of the number. If these values match, the number meets the criteria for being classified as an Adam number; otherwise, it does not fulfill the condition.

Input Required

This code uses input(). Please provide values below: