Ask Question
7 January, 15:01

Read an integer from keyboard and then print the result of the sum obtained by adding the entered integer to the integer formed by reversing the order of the digits. (For example: entered number = 123. Sum = 123+321 = 444)

+2
Answers (1)
  1. 7 January, 15:06
    0
    Following are the program in C+ + language

    #include / / header file

    using namespace std; / / namespace std;

    int main () / / main function

    {

    int number, n1, rem; / / variable declaration

    int sum, sum1=0; / / variable declaration

    cout<<"Enter the number : ";

    cin>>number; / / Read the number

    n1=number; / / initialized the value of number with the n1

    while (n1>0) / / iteating the while loop

    {

    rem=n1%10; / / finding the reminder

    sum1=10*sum1+rem; / / storing the sum

    n1=n1/10;

    }

    sum=sum1+number; / / calculate the sum

    cout<<"The sum is:"<
    return 0;

    }

    Output:

    Enter the number : 123

    The sum is:444

    Explanation:

    Following are the Description of the Program

    Read the value of "number" in the "number" variable of int type. Initialized the value of "number" in the "n1' variable. Iterating the while loop until the n1>0. In this loop we reverse the number in the "sum1" variable Finally print the sum in the "sum" variable
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Read an integer from keyboard and then print the result of the sum obtained by adding the entered integer to the integer formed by ...” 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