Start with a modulus suffix check. Then list a range, and finish with a readable string ends-with variant.
Example 1 — Check One Number
Count digits, take (n * n) % pow10(k), and compare with n.
C
#include <stdio.h>
long long pow10(int k) {
long long p = 1LL;
int i;
for (i = 0; i < k; i++) {
p *= 10LL;
}
return p;
}
int isAutomorphic(int n) {
int k = 0;
int t;
long long square;
if (n <= 0) {
return 0;
}
for (t = n; t > 0; t /= 10) {
k++;
}
square = (long long) n * (long long) n;
return square % pow10(k) == n;
}
int main(void) {
int number = 76;
if (isAutomorphic(number)) {
printf("%d is an automorphic number.\n", number);
} else {
printf("%d is not an automorphic number.\n", number);
}
return 0;
}
Output
76 is an automorphic number.
How It Works
Return 0 for non-positive inputs.
Count digits into k by dividing a copy by 10.
Square with long long so n * n does not overflow int.
Isolate the last k digits with square % pow10(k).
Equality with n is the whole definition.
Example 2 — Automorphic Numbers from 1 to 50
Reuse the helper and print every match in a closed range.
C
#include <stdio.h>
long long pow10(int k) {
long long p = 1LL;
int i;
for (i = 0; i < k; i++) {
p *= 10LL;
}
return p;
}
int isAutomorphic(int n) {
int k = 0;
int t;
long long square;
if (n <= 0) {
return 0;
}
for (t = n; t > 0; t /= 10) {
k++;
}
square = (long long) n * (long long) n;
return square % pow10(k) == n;
}
int main(void) {
int start = 1;
int end = 50;
int value;
printf("Automorphic numbers in the range %d to %d:\n", start, end);
for (value = start; value <= end; value++) {
if (isAutomorphic(value)) {
printf("%d ", value);
}
}
printf("\n");
return 0;
}
Output
Automorphic numbers in the range 1 to 50:
1 5 6 25
How It Works
Loop from start to end inclusive.
Call isAutomorphic(value) for each value.
Print only the matches.
Within 1…50 you should see 1, 5, 6, and 25.
The helper stays pure; the loop only decides what to print.
Example 3 — String Suffix Check
Convert the square to text and ask whether it ends with the digits of n.