Thursday 18 April 2019

Check whether a given number is Automorphic number or not

// C program to check whether the number is automorphic or not
#include<stdio.h>
bool isAutomorphic(int N)
{
int sq = N * N;
while (N > 0)
{
if (N % 10 != sq % 10)
return false;
// Reduce N and square
N /= 10;
sq /= 10;
}
return true;
}
int main()
{
//Fill the code
int N;
scanf(“%d”,&N);
isAutomorphic(N) ? printf(“Automorphic”) : printf(“Not Automorphic”);
return 0;
}

No comments:

Post a Comment

Amazon1Ads