An Automorphic Number is a number whose square ends with the same digits as the number itself. In other words, a number N
is Automorphic if the last digits of N²
are the same as N
.
Examples of Non-Automorphic Numbers
N
."Automorphic Number"
if N
is Automorphic."Not an Automorphic Number"
.Input:
CopyEdit25
Output:
javascriptCopyEditAutomorphic Number
Explanation:
252=62525^2 = 625252=625 → Ends with 25
Input:
CopyEdit12
Output:
mathematicaCopyEditNot an Automorphic Number
Explanation:
122=14412^2 = 144122=144 → Does not end with 12
N
from the user.N
, i.e., N²
.N²
match N
:N
and N²
to strings.N²
equal to the length of N
.cCopyEdit#include <stdio.h>
// Function to check if a number is Automorphic
int isAutomorphic(int num) {
int square = num * num;
// Temporary variable to extract last digits
int temp = num;
while (temp > 0) {
// If the last digits do not match, return false
if (square % 10 != temp % 10) {
return 0;
}
square /= 10;
temp /= 10;
}
return 1;
}
int main() {
int num;
// Input the number
printf("Enter a number: ");
scanf("%d", &num);
// Check if the number is Automorphic
if (isAutomorphic(num)) {
printf("Automorphic Number\n");
} else {
printf("Not an Automorphic Number\n");
}
return 0;
}
isAutomorphic(int num)
num
and square
.% 10
) and removes them using division (/ 10
).isAutomorphic()
to check if the number is Automorphic.Input | Expected Output |
---|---|
5 | Automorphic Number |
6 | Automorphic Number |
25 | Automorphic Number |
76 | Automorphic Number |
7 | Not an Automorphic Number |
12 | Not an Automorphic Number |
5
and 6
) should be handled correctly.10, 100, 1000
) should be tested.Advantages:
Disadvantages:
An Automorphic Number is a number whose square ends with the same digits as the number itself. The provided C program efficiently checks Automorphic numbers using modulus and division operations. By running test cases and optimizing the approach, we ensure correct and efficient execution.