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;