Dremendo Tag Line

Product of first and last digit in C++

cin - Question 6

In this question, we will see how to input a three digit number in C++ programming using the cin statement and find the product of its first and last digit. To know more about cin statement click on the cin statement lesson.

Q6) Write a program in C++ to input a three digit number and find the product of its first and last digit.

Program

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
    int n,fd,ld,pr;
    cout<<"Enter a three digit number\n";
    cin>>n;
    fd=n/100;
    ld=n%10;
    pr=fd*ld;
    cout<<"First digit="<<fd<<endl;
    cout<<"Last digit="<<ld<<endl;
    cout<<"Product of first and last digit="<<pr;
    return 0;
}

Output

Enter a three digit number
854
First digit=8
Last digit=4
Product of first and last digit=32
video-poster