Ask Question
29 July, 23:40

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)

+4
Answers (1)
  1. 29 July, 23:46
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers