Product of first and last digit in C
scanf() - Question 6
In this question, we will see how to input a three digit number in C programming using the scanf() function and find the product of its first and last digit. To know more about scanf() function click on the scanf() function 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 <stdio.h>
#include <conio.h>
int main()
{
int n,fd,ld,pr;
printf("Enter a three digit number\n");
scanf("%d",&n);
fd=n/100;
ld=n%10;
pr=fd*ld;
printf("First digit=%d\n",fd);
printf("Last digit=%d\n",ld);
printf("Product of first and last digit=%d",pr);
return 0;
}
Output
Enter a three digit number 854 First digit=8 Last digit=4 Product of first and last digit=32