Answers for "sum given find first and last in ap in c++"

C++
0

Sum of first and last digit of a number in C++

// not my code but I figured it would be useful

int number, sum=0, firstDigit, lastDigit;

     //Reading a number from user
    cout<<"Enter any number:";
    cin>>number;

     lastDigit = number % 10;

    firstDigit = number;

    while(number >= 10)
    {
        number = number / 10;
    }
    firstDigit = number;

     //Finding sum of first and last digit
    sum = firstDigit + lastDigit;

    cout<<"Sum of first and last digit: "<<sum;
Posted by: Guest on December-30-2020

Code answers related to "sum given find first and last in ap in c++"

Browse Popular Code Answers by Language