Ask Question

Program on automorphic number

+5
Answers (1)
  1. 13 July, 05:08
    0
    The program to this question can be given as:

    Program:

    #include//header file.

    using namespace std; / /using name namespace

    void number (int n) / /define function

    {

    int temp, s, c=1; / /define variable.

    temp=n; / /holding value in temp variable.

    s=n*n; / / calculate square.

    while (n!=0) / /loop

    {

    //calculating value.

    c=c*10;

    n=n/10;

    }

    if (s%c==temp) / /if block

    {

    cout<<"Automorphic Number"; / /print message.

    }

    else / /else block

    {

    cout<<"Not Automorphic Number"; / /print message.

    }

    }

    int main () / /main method

    {

    int n; / /define variable n.

    cout<<"Enter a number : "; / /message

    cin>> n; / /input value.

    number (n); / /calling function.

    return 0;

    }

    Output:

    Enter a number : 5

    Automorphic Number

    Explanation:

    An Automorphic number is a value in which the square end has the same numbers as a number itself. The explanation of the above program as follows:

    In the above automorphic number program, we define a function that is "number () " in the function, we pass variable n that is integer. Inside a function, we define a variable that is "temp, s, and c". The temp variable is used to for copy the number, s, and c variable is used for calculating the automorphic number. In the function, we define a loop that is "while loop" it entry control loop, in loop we define a conditional statement that checks that the calculated value which holds variable s and temp value is equal or not if condition is true, it will print "Automorphic Number" else it will print "Not Automorphic Number". Then we define the main method in the method we define a variable n and take value-form user and pass value to function then we call the function.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Program on automorphic number ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers