Check Whether a Number is Automorphic Number or Not in C using Function
ADVERTISEMENTS
Check whether a number is automorphic number or not in C using function. In this article, you will learn how to check whether a number is automorphic number or not in c using function.
Source Code
// Check Whether a Number is Automorphic Number or Not in C using Function
#include <stdio.h>
int isAutomorphic(int x);
// It's the driver function
int main() {
int x;
// x - denotes the input number to check
printf("-----Enter an input number to check, It's an automorphic-----\n");
scanf("%d", &x);
//checking condition
if (isAutomorphic(x)) {
printf("\nThis is an automorphic number\n");
} else {
printf("\nThis is not an automorphic number\n");
}
return 0;
}
// This function will check number itself
int isAutomorphic(int x) {
int sq = x * x;
// sq - denotes the square
while (x > 0) {
if (x % 10 != sq % 10)
return 0;
// Reduce N and square
x = x / 10;
sq = sq / 10;
}
return 1;
}
Output
-----Enter an input number to check, It's an automorphic-----
456
This is not an automorphic number