write a program in C++ to enter on three digt
number and print the sum of of first and last
digit of the number
Answers
#include <iostream>
using namespace std;
int main()
{
int n,first,last,sum;
cout << "\n\n Find the sum of first and last digit of a number:\n";
cout << "------------------------------------------------------\n";
cout << " Input any number: ";
cin >> n;
first = n;
last=n % 10;
for(first=n;first>=10;first=first/10);
cout<<" The first digit of "<<n<<" is: "<<first<<endl;
cout<<" The last digit of "<<n<<" is: "<<last<<endl;
cout<<" The sum of first and last digit of "<<n<<" is: "<<first+last<<endl;
}
HOPE YOU MARK AS BRAINLIEST
#include<stdio.h>
int main()
{
printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");
int input, firstNumber, lastNumber;
printf("Enter a number: ");
scanf("%d", &input);
/*
gives remainder when the input value is divided by 10
i.e. the digit at units place
*/
lastNumber = input%10;
firstNumber = input;
while(firstNumber >= 10)
{
firstNumber /= 10; // same as firstNumber = firstNumber/10
}
printf("\n\n\nAddition of first and last number is: %d + %d = %d\n", firstNumber, lastNumber, firstNumber+lastNumber);
printf("\n\n\t\t\tCoding is Fun !\n\n\n");
return 0;
}