Automorphic Number

Here given code implementation process.

``````/*
C Program
Check if a given number is Automorphic number or not

*/
#include<stdio.h>

//Determine whether number is Automorphic number
void automorphic_no(int number)
{
if(number==0)
{
return ;
}
//make square of given number
long squre = number * number;

int auxiliary = number;
//Indicates Automorphic number or not
int flag = 1;

while(flag == 1 && squre!=0 && auxiliary !=0)
{
//Compare last digit
if(squre%10 != auxiliary%10)
{
//When not a same last digit to both numbers
flag = 0;
}
//Remove last digit
auxiliary/=10;
squre/=10;
}
if(flag==0)
{
printf("%d Is not an Automorphic Number\n",number );
}
else
{
printf("%d Is an Automorphic Number \n",number );
}

}
int main(){

//Test Case
automorphic_no(6);
automorphic_no(36);
automorphic_no(42);
automorphic_no(25);
return 0;
}```
```

Output

``````6 Is an Automorphic Number
36 Is not an Automorphic Number
42 Is not an Automorphic Number
25 Is an Automorphic Number``````
``````/*
C++ Program
Check if a given number is Automorphic number or not
*/

#include<iostream>

using namespace std;

class MyNumber {
public:

//Determine whether number is Automorphic number
void automorphic_no(int number) {
if (number == 0) {
return;
}
//make square of given number
long squre = number *number;
int auxiliary = number;
//Indicates Automorphic number or not
bool flag = true;
while (flag == true && squre != 0 && auxiliary != 0) {
//Compare last digit

if (squre % 10 != auxiliary % 10) {
//When not a same last digit to both numbers
flag = false;
}
//Remove last digit
auxiliary /= 10;
squre /= 10;
}
if (flag == false) {
cout << number << " Is not an Automorphic Number\n";
} else {
cout << number << " Is an Automorphic Number \n";
}
}
};
int main() {
MyNumber obj;
//Test Case
obj.automorphic_no(6);
obj.automorphic_no(36);
obj.automorphic_no(42);
obj.automorphic_no(25);
return 0;
}```
```

Output

``````6 Is an Automorphic Number
36 Is not an Automorphic Number
42 Is not an Automorphic Number
25 Is an Automorphic Number``````
``````/*
Java Program
Check if a given number is Automorphic number or not
*/
public class MyNumber {

//Determine whether number is Automorphic number
public void automorphic_no(int number)
{
if(number==0)
{
return ;
}
//make square of given number
long squre = number * number;

int auxiliary = number;
//Indicates Automorphic number or not
boolean flag = true;

while(flag == true && squre!=0 && auxiliary !=0)
{
//Compare last digit
if(squre%10 != auxiliary%10)
{
//When not a same last digit to both numbers
flag = false;
}
//Remove last digit
auxiliary/=10;
squre/=10;
}
if(flag==false)
{
System.out.print(number+" Is not an Automorphic Number\n" );
}
else
{
System.out.print(number+" Is an Automorphic Number \n" );
}

}

public static void main(String[] args) {

MyNumber obj = new MyNumber();

//Test Case
obj.automorphic_no(6);
obj.automorphic_no(36);
obj.automorphic_no(42);
obj.automorphic_no(25);
}
}```
```

Output

``````6 Is an Automorphic Number
36 Is not an Automorphic Number
42 Is not an Automorphic Number
25 Is an Automorphic Number``````
``````/*
C# Program
Check if a given number is Automorphic number or not
*/
using System;
public class MyNumber {

//Determine whether number is Automorphic number
public void automorphic_no(int number) {
if (number == 0) {
return;
}
//make square of given number
long squre = number * number;

int auxiliary = number;
//Indicates Automorphic number or not
Boolean flag = true;

while (flag == true && squre != 0 && auxiliary != 0) {
//Compare last digit
if (squre % 10 != auxiliary % 10) {
//When not a same last digit to both numbers
flag = false;
}
//Remove last digit
auxiliary /= 10;
squre /= 10;
}
if (flag == false) {
Console.Write(number + " Is not an Automorphic Number\n");
} else {
Console.Write(number + " Is an Automorphic Number \n");
}

}

public static void Main(String[] args) {

MyNumber obj = new MyNumber();

//Test Case
obj.automorphic_no(6);
obj.automorphic_no(36);
obj.automorphic_no(42);
obj.automorphic_no(25);
}
}```
```

Output

``````6 Is an Automorphic Number
36 Is not an Automorphic Number
42 Is not an Automorphic Number
25 Is an Automorphic Number``````
``````# Python 3 Program
# Check if a given number is Automorphic number or not
class MyNumber :
# Determine whether number is Automorphic number
def automorphic_no(self, number) :
if (number == 0) :
return

# make square of given number
squre = number * number
auxiliary = number
# Indicates Automorphic number or not
flag = True
while (flag == True and squre != 0 and auxiliary != 0) :
# Compare last digit

if (squre % 10 != auxiliary % 10) :
# When not a same last digit to both numbers
flag = False

auxiliary = int(auxiliary /
# Remove last digit
10)
squre = int(squre / 10)

if (flag == False) :
print(number ," Is not an Automorphic Number")
else :
print(number ," Is an Automorphic Number")

def main() :
obj = MyNumber()
# Test Case
obj.automorphic_no(6)
obj.automorphic_no(36)
obj.automorphic_no(42)
obj.automorphic_no(25)

if __name__ == "__main__":
main()```
```

Output

``````6 Is an Automorphic Number
36 Is not an Automorphic Number
42 Is not an Automorphic Number
25 Is an Automorphic Number``````
``````# Ruby Program
# Check if a given number is Automorphic number or not
class MyNumber
# Determine whether number is Automorphic number
def automorphic_no(number)
if (number == 0)
return
end
# make square of given number
squre = number * number
auxiliary = number
# Indicates Automorphic number or not
flag = true
while (flag == true and squre != 0 and auxiliary != 0)
# Compare last digit

if (squre % 10 != auxiliary % 10)
# When not a same last digit to both numbers
flag = false
end
# Remove last digit
auxiliary /= 10
squre /= 10
end
if (flag == false)
print(number ," Is not an Automorphic Number\n")
else
print(number ," Is an Automorphic Number \n")
end
end
end
def main()
obj = MyNumber.new()
# Test Case
obj.automorphic_no(6)
obj.automorphic_no(36)
obj.automorphic_no(42)
obj.automorphic_no(25)
end
main()```
```

Output

``````6 Is an Automorphic Number
36 Is not an Automorphic Number
42 Is not an Automorphic Number
25 Is an Automorphic Number
``````
``````/*
Scala Program
Check if a given number is Automorphic number or not
*/
class MyNumber {
//Determine whether number is Automorphic number
def automorphic_no(number: Int): Unit = {
if (number == 0) {
return;
}
//make square of given number
var squre: Long = number * number;
var auxiliary: Int = number;
//Indicates Automorphic number or not
var flag: Boolean = true;
while (flag == true && squre != 0 && auxiliary != 0) {
//Compare last digit

if (squre % 10 != auxiliary % 10) {
//When not a same last digit to both numbers
flag = false;
}
auxiliary = (auxiliary / 10).toInt;
//Remove last digit
squre = (squre / 10).toInt;
}
if (flag == false) {
print(s"\$number Is not an Automorphic Number\n");
} else {
print(s"\$number Is an Automorphic Number \n");
}
}
}
object Main {
def main(args: Array[String]): Unit = {
var obj: MyNumber = new MyNumber();
//Test Case
obj.automorphic_no(6);
obj.automorphic_no(36);
obj.automorphic_no(42);
obj.automorphic_no(25);
}
}```
```

Output

``````6 Is an Automorphic Number
36 Is not an Automorphic Number
42 Is not an Automorphic Number
25 Is an Automorphic Number``````
``````/*
Swift 4 Program
Check if a given number is Automorphic number or not
*/
class MyNumber {
//Determine whether number is Automorphic number
func automorphic_no(_ number: Int) {
if (number == 0) {
return;
}
//make square of given number
var squre: Int = number * number;
var auxiliary: Int = number;
//Indicates Automorphic number or not
var flag: Bool = true;
while (flag == true && squre != 0 && auxiliary != 0) {
//Compare last digit

if (squre % 10 != auxiliary % 10) {
//When not a same last digit to both numbers
flag = false;
}
//Remove last digit
auxiliary /= 10;
squre /= 10;
}
if (flag == false) {
print(number ," Is not an Automorphic Number");
} else {
print(number ," Is an Automorphic Number ");
}
}
}
func main() {
let obj: MyNumber = MyNumber();
//Test Case
obj.automorphic_no(6);
obj.automorphic_no(36);
obj.automorphic_no(42);
obj.automorphic_no(25);
}
main();```
```

Output

``````6  Is an Automorphic Number
36  Is not an Automorphic Number
42  Is not an Automorphic Number
25  Is an Automorphic Number``````
``````<?php
/*
Php Program
Check if a given number is Automorphic number or not
*/
class MyNumber {
//Determine whether number is Automorphic number

public 	function automorphic_no(\$number) {
if (\$number == 0) {
return;
}
//make square of given number
\$squre = \$number *\$number;
\$auxiliary = \$number;
//Indicates Automorphic number or not
\$flag = true;
while (\$flag == true && \$squre != 0 && \$auxiliary != 0) {
//Compare last digit

if (\$squre % 10 != \$auxiliary % 10) {
//When not a same last digit to both numbers
\$flag = false;
}
//Remove last digit
\$auxiliary = intval(\$auxiliary / 10);
\$squre = intval(\$squre / 10);
}
if (\$flag == false) {
echo(\$number ." Is not an Automorphic Number\n");
} else {
echo(\$number ." Is an Automorphic Number \n");
}
}
};

function main() {
\$obj = new MyNumber();
//Test Case

\$obj->automorphic_no(6);
\$obj->automorphic_no(36);
\$obj->automorphic_no(42);
\$obj->automorphic_no(25);
}
main();```
```

Output

``````6 Is an Automorphic Number
36 Is not an Automorphic Number
42 Is not an Automorphic Number
25 Is an Automorphic Number``````
``````/*
Node Js Program
Check if a given number is Automorphic number or not
*/
class MyNumber {
//Determine whether number is Automorphic number
automorphic_no(number) {
if (number == 0) {
return;
}
//make square of given number
var squre = number *number;
var auxiliary = number;
//Indicates Automorphic number or not
var flag = true;
while (flag == true && squre != 0 && auxiliary != 0) {
//Compare last digit

if (squre % 10 != auxiliary % 10) {
//When not a same last digit to both numbers
flag = false;
}
//Remove last digit
auxiliary = parseInt(auxiliary / 10);
squre = parseInt(squre / 10);
}
if (flag == false) {
process.stdout.write(number + " Is not an Automorphic Number\n");
} else {
process.stdout.write(number + " Is an Automorphic Number \n");
}
}
}

function main(args) {
var obj = new MyNumber();
//Test Case
obj.automorphic_no(6);
obj.automorphic_no(36);
obj.automorphic_no(42);
obj.automorphic_no(25);
}
main();```
```

Output

``````6 Is an Automorphic Number
36 Is not an Automorphic Number
42 Is not an Automorphic Number
25 Is an Automorphic Number``````

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.