Program to delete duplicates from a link list

Check if a number is Automorphic number

What is Automorphic number : –

A number is said to be automorphic if it’s square is end with same digits as number itself.

for Example:-  (5)²= 125  ( since 125 end with 5 so it is an Automorphic number )

2. (25)² = 625   ( since 625 end with 25 so it is an Automorphic number)

3. (376)²= 141376  ( since 141376 end with 376 so it is an Automorphic number)

Code in c++:- 

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cout<<"Enter a number\n";
    cin>>n;
    
    // count the number of digits
    int n1=n,dig=0;
    while(n1!=0)
    {
        dig+=1;
        n1/=10;
    }
    
    long long sq=pow(n,2);
    // finding the divisor
    long long divisor=pow(10,dig);
    // finding the number from the last of the squared number
    int last=sq%(divisor);
    
    // if number is finding from last of the squared number
    // is equal 
    if(last==n)
      cout<<n<<"  is a Automorphic number"<<endl;
    else
      cout<<n<<" is not a Automorphic number"<<endl;
     return 0;
}

Output:-

Enter a number
25
25  is a Automorphic number

python code:-

import math
n=int(input())
x=n*n 
s=str(n)
n1=len(s)
n2=pow(10,n1)
res=x%n2
if (res)==n:
    print(n,"is a Automorphic number ")
else:
    print(n,"is not a Automorphic number ")

output:-

6
6 is a Automorphic number

 

Also check this:-

codechef problems:-

Wipro :-

Infytq :-

Key Points;-

Hackerrank:-

C-tutorial:-

See more:-

Leave a Reply

Your email address will not be published.