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:-
- Primary test
- Sum or difference
- point and line
Wipro :-
- Update the booking ID | Wipro previous year question paper solution
- Pages in PDF
- Find the location id
- Find the odd digits
- Find the Product ID
Infytq :-
Key Points;-
Hackerrank:-
- Python : missing characters : hackerrank solution
- Python : string transformation | Hackerrank solution
- Active Traders certification test problem | Hackerrank Solution
- Usernames changes certification test problem | Hackerrank Solution
- string Representation of objects certification test hackerrank solution
- Average Function | hackerrank certification problem solution
C-tutorial:-
- Micros in C
- Pointer in c
- Function declaration
- Types of user define function
- return type of function
- 2D array
See more:-
- c program to convert specified days into years weeks and days
- Print Reverse Hollow Pyramid
- Update the booking ID | Wipro previous year question paper
- Pages in PDF | Wipro previous year question paper
- Sparse Matrix in data structure
- Find the location ID | Wipro previous year Coding question
- find the odd digits | Wipro Coding question
- Find the product id | Wipro Coding question
- Difference between static and dynamic memory allocation
- What is asymptotic Notation