sum of first and last digit of a number in c 2b 2b

Solutions on MaxInterview for sum of first and last digit of a number in c 2b 2b by the best coders in the world

showing results for - "sum of first and last digit of a number in c 2b 2b"
Calie
28 Oct 2018
1// not my code but I figured it would be useful
2
3int number, sum=0, firstDigit, lastDigit;
4
5     //Reading a number from user
6    cout<<"Enter any number:";
7    cin>>number;
8
9     lastDigit = number % 10;
10
11    firstDigit = number;
12
13    while(number >= 10)
14    {
15        number = number / 10;
16    }
17    firstDigit = number;
18
19     //Finding sum of first and last digit
20    sum = firstDigit + lastDigit;
21
22    cout<<"Sum of first and last digit: "<<sum;